Add PostgreSQL PARTITION OF syntax support#2127
Conversation
src/parser/mod.rs
Outdated
| // PostgreSQL PARTITION OF for child partition tables | ||
| let partition_of = if dialect_of!(self is PostgreSqlDialect | GenericDialect) | ||
| && self.parse_keywords(&[Keyword::PARTITION, Keyword::OF]) |
There was a problem hiding this comment.
| // PostgreSQL PARTITION OF for child partition tables | |
| let partition_of = if dialect_of!(self is PostgreSqlDialect | GenericDialect) | |
| && self.parse_keywords(&[Keyword::PARTITION, Keyword::OF]) | |
| let partition_of = if self.parse_keywords(&[Keyword::PARTITION, Keyword::OF]) |
If possible we can skiip the dialect check and let the parser accept the PARTITION OF clause whenever it shows up in an input sql
src/parser/mod.rs
Outdated
| } | ||
| } | ||
|
|
||
| /// Parse a single partition bound value (MINVALUE, MAXVALUE, or expression). |
There was a problem hiding this comment.
| /// Parse a single partition bound value (MINVALUE, MAXVALUE, or expression). | |
| /// Parse a single [PartitionBoundValue]. |
src/ast/ddl.rs
Outdated
| } | ||
| } | ||
|
|
||
| /// PostgreSQL partition bound specification for PARTITION OF. |
There was a problem hiding this comment.
| /// PostgreSQL partition bound specification for PARTITION OF. | |
| /// PostgreSQL partition bound specification for `PARTITION OF`. |
src/parser/mod.rs
Outdated
| /// Parse PostgreSQL partition bound specification for PARTITION OF. | ||
| /// | ||
| /// Parses: `FOR VALUES partition_bound_spec | DEFAULT` |
There was a problem hiding this comment.
| /// Parse PostgreSQL partition bound specification for PARTITION OF. | |
| /// | |
| /// Parses: `FOR VALUES partition_bound_spec | DEFAULT` | |
| /// Parse [ForValues] of a `PARTITION OF` clause. |
|
just in case @fmguerreiro please feel free to re-request review when ready |
tests/sqlparser_postgres.rs
Outdated
| Box::new(PostgreSqlDialect {}), | ||
| Box::new(MySqlDialect {}), | ||
| Box::new(SQLiteDialect {}), | ||
| ]); |
There was a problem hiding this comment.
If the intent is to test all dialects I think the test could live in sqlparser_common.rs and shouldn't explicitly list the dialects rather it can use all_dialects() - if the syntax conflicts across dialects (thinking probably snowflake for example) then I would suggest we just skip this test and rely on the pg_and_generic coverage after all
d85fe74 to
690091c
Compare
- Add explicit check for FOR/DEFAULT after PARTITION OF with clear error message - Document intentional removal of dialect check for multi-dialect tool support - Add negative test cases for malformed PARTITION OF syntax
690091c to
904896d
Compare
iffyio
left a comment
There was a problem hiding this comment.
LGTM! Thanks @fmguerreiro!
Summary
This PR adds support for PostgreSQL's
CREATE TABLE ... PARTITION OFsyntax for creating child partition tables.Closes #2042
Changes
MODULUSandREMAINDERkeywords tosrc/keywords.rsForValuesenum andPartitionBoundValueenum tosrc/ast/ddl.rswith Display implementationspartition_ofandfor_valuesfields toCreateTablestructCreateTableBuilderinsrc/ast/helpers/stmt_create_table.rssrc/parser/mod.rsforPARTITION OF,FOR VALUES IN/FROM/TO/WITH, andDEFAULTsrc/ast/spans.rsto include new fieldssrc/ast/mod.rstests/sqlparser_postgres.rsSupported Syntax
Testing
cargo fmtpassesPostgreSqlDialectandGenericDialectas required