Skip to content

PostgreSQL: Column entries in CREATE TABLE ... PARTITION OF are parsed as typed columns #2762

Open

Description

@s5dsn-eqee

Problem

In the PARTITION OF form, PostgreSQL column entries have no data type (docs):

PARTITION OF parent_table [ (
  { column_name [ WITH OPTIONS ] [ column_constraint [ ... ] ]
    | table_constraint }
    [, ... ]
) ] { FOR VALUES partition_bound_spec | DEFAULT }

The parser always reads a data type after the column name, so the first constraint keyword is taken as the type

  let stmt = pg().verified_stmt("CREATE TABLE part PARTITION OF root (id NOT NULL) DEFAULT");
  println!("{stmt:#?}");

Result:

    [
         CreateTable(
             CreateTable {
                 or_replace: false,
                 temporary: false,
                 unlogged: false,
                 external: false,
                 dynamic: false,
                 global: None,
                 if_not_exists: false,
                 transient: false,
                 volatile: false,
                 iceberg: false,
                 snapshot: false,
                 name: ObjectName(
                     [
                         Identifier(
                             Ident {
                                 value: "part",
                                 quote_style: None,
                                 span: Span(Location(1,14)..Location(1,18)),
                             },
                         ),
                     ],
                 ),
                 columns: [
                     ColumnDef {
                         name: Ident {
                             value: "id",
                             quote_style: None,
                             span: Span(Location(1,38)..Location(1,40)),
                         },
                         data_type: Custom(
                             ObjectName(
                                 [
                                     Identifier(
                                         Ident {
                                             value: "NOT",
                                             quote_style: None,
                                             span: Span(Location(1,41)..Location(1,44)),
                                         },
                                     ),
                                 ],
                             ),
                             [],
                         ),
                         options: [
                             ColumnOptionDef {
                                 name: None,
                                 option: Null,
                             },
                         ],
                     },
                 ],
                 constraints: [],
                 hive_distribution: NONE,
                 hive_formats: None,
                 table_options: None,
                 file_format: None,
                 location: None,
                 query: None,
                 sqlite_table_options: SqliteTableOptions {
                     leading_comma: false,
                     options: [],
                 },
                 like: None,
                 clone: None,
                 version: None,
                 comment: None,
                 on_commit: None,
                 on_cluster: None,
                 primary_key: None,
                 order_by: None,
                 partition_by: None,
                 cluster_by: None,
                 clustered_by: None,
                 inherits: None,
                 partition_of: Some(
                     ObjectName(
                         [
                             Identifier(
                                 Ident {
                                     value: "root",
                                     quote_style: None,
                                     span: Span(Location(1,32)..Location(1,36)),
                                 },
                             ),
                         ],
                     ),
                 ),
                 for_values: Some(
                     Default,
                 ),
                 copy_grants: false,
                 enable_schema_evolution: None,
                 change_tracking: None,
                 data_retention_time_in_days: None,
                 max_data_extension_time_in_days: None,
                 default_ddl_collation: None,
                 with_aggregation_policy: None,
                 with_row_access_policy: None,
                 with_storage_lifecycle_policy: None,
                 with_tags: None,
                 external_volume: None,
                 with_connection: None,
                 base_location: None,
                 catalog: None,
                 catalog_sync: None,
                 storage_serialization_policy: None,
                 target_lag: None,
                 warehouse: None,
                 refresh_mode: None,
                 initialize: None,
                 require_user: false,
                 catalog_sync: None,
                 storage_serialization_policy: None,
                 target_lag: None,
                 warehouse: None,
                 refresh_mode: None,
                 initialize: None,
                 require_user: false,
                 diststyle: None,
                 distkey: None,
                 sortkey: None,
                 backup: None,
                 multiset: None,
                 fallback: None,
                 with_data: None,
             },
         ),
     ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions