fmguerreiro opened a new pull request, #2127:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2127
## Summary
This PR adds support for PostgreSQL's `CREATE TABLE ... PARTITION OF` syntax
for creating child partition tables.
Closes #2042
## Changes
- Added `MODULUS` and `REMAINDER` keywords to `src/keywords.rs`
- Added `ForValues` enum and `PartitionBoundValue` enum to `src/ast/ddl.rs`
with Display implementations
- Added `partition_of` and `for_values` fields to `CreateTable` struct
- Updated `CreateTableBuilder` in `src/ast/helpers/stmt_create_table.rs`
- Added parser logic in `src/parser/mod.rs` for `PARTITION OF`, `FOR VALUES
IN/FROM/TO/WITH`, and `DEFAULT`
- Updated `src/ast/spans.rs` to include new fields
- Exported new types from `src/ast/mod.rs`
- Added 7 comprehensive tests in `tests/sqlparser_postgres.rs`
## Supported Syntax
```sql
-- RANGE partition
CREATE TABLE t PARTITION OF parent FOR VALUES FROM ('2023-01-01') TO
('2024-01-01');
-- RANGE with MINVALUE/MAXVALUE
CREATE TABLE t PARTITION OF parent FOR VALUES FROM (MINVALUE) TO
('2020-01-01');
-- LIST partition
CREATE TABLE t PARTITION OF parent FOR VALUES IN ('US', 'CA', 'MX');
-- HASH partition
CREATE TABLE t PARTITION OF parent FOR VALUES WITH (MODULUS 4, REMAINDER 0);
-- DEFAULT partition
CREATE TABLE t PARTITION OF parent DEFAULT;
-- Multi-column range
CREATE TABLE t PARTITION OF parent FOR VALUES FROM ('2023-01-01', 1) TO
('2023-04-01', 1);
-- With table constraints
CREATE TABLE t PARTITION OF parent (
CONSTRAINT check_date CHECK (order_date >= '2023-01-01')
) FOR VALUES FROM ('2023-01-01') TO ('2024-01-01');
```
## Testing
- All 7 new partition tests pass
- All 1312 existing tests pass (no regressions)
- `cargo fmt` passes
- Works with both `PostgreSqlDialect` and `GenericDialect` as required
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]