iffyio commented on code in PR #1806: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1806#discussion_r2038856032
########## tests/sqlparser_postgres.rs: ########## @@ -2733,6 +2733,39 @@ fn parse_create_brin() { } } +#[test] +fn parse_create_table_with_inherits() { + let single_inheritance_sql = + "CREATE TABLE child_table (child_column INT) INHERITS (public.parent_table)"; + match pg().verified_stmt(single_inheritance_sql) { + Statement::CreateTable(CreateTable { + inherits: Some(inherits), + .. + }) => { + assert_eq_vec(&["public", "parent_table"], &inherits[0].0); + } + _ => unreachable!(), + } + + let double_inheritance_sql = "CREATE TABLE child_table (child_column INT) INHERITS (public.parent_table, pg_catalog.pg_settings)"; + match pg().verified_stmt(double_inheritance_sql) { + Statement::CreateTable(CreateTable { + inherits: Some(inherits), + .. + }) => { + assert_eq_vec(&["public", "parent_table"], &inherits[0].0); + assert_eq_vec(&["pg_catalog", "pg_settings"], &inherits[1].0); + } + _ => unreachable!(), + } +} + +#[test] +#[should_panic] +fn parse_create_table_with_empty_inherits_fails() { + pg().verified_stmt("CREATE TABLE child_table (child_column INT) INHERITS ()"); Review Comment: in place of the `should_panic`, we can rewrite the test case [in this form](https://github.com/apache/datafusion-sqlparser-rs/blob/165164bfc2d19fc61b3caec3fec2265c9173766a/tests/sqlparser_postgres.rs#L307-L310) It would let us include the test case in the existing test function `parse_create_table_with_inherits` to help with grouping related test cases ########## src/parser/mod.rs: ########## @@ -7070,13 +7071,22 @@ impl<'a> Parser<'a> { } } - /// Parse configuration like partitioning, clustering information during the table creation. + /// Parse configuration like inheritance, partitioning, clustering information during the table creation. /// /// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#syntax_2) - /// [PostgreSQL](https://www.postgresql.org/docs/current/ddl-partitioning.html) + /// [PostgreSQL Partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html) + /// [PostgreSQL Inheritance](https://www.postgresql.org/docs/current/ddl-inherit.html) fn parse_optional_create_table_config( &mut self, ) -> Result<CreateTableConfiguration, ParserError> { + let inherits = if dialect_of!(self is BigQueryDialect | PostgreSqlDialect | GenericDialect) Review Comment: the `dialect_of` macro we're transitioning away from for new code, but I think in this case there's probably no need to gate this on dialect (also not sure BQ supports this syntax so it might be misleading to explicitly name BQ here) so that we can remove the check entirely and always parse the `INHERIT` option if it shows up in the statement? -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org