云数据库 GAUSSDB-CREATE TABLE PARTITION:语法格式

时间:2024-12-19 14:11:21

语法格式

CREATE TABLE [ IF NOT EXISTS ] partition_table_name
{ ( [ 
    { column_name data_type [ CHARACTER SET | CHARSET charset ] [ COLLATE collation ] [ column_constraint [ ... ] ]
    | table_constraint
    | LIKE source_table [ like_option [...] ] }
    [, ... ]
] )
    | LIKE source_table }
    [ table_option [ [ , ] ... ] ]
    [ htap_option ]
    [ WITH ( {storage_parameter = value} [, ... ] ) ]
    [ ILM ADD POLICY ROW STORE COMPRESS ADVANCED ROW AFTER n { day | month | year } OF NO MODIFICATION [ ON ( EXPR )]]
    [ TABLESPACE tablespace_name ]
     PARTITION BY { 
        {RANGE [COLUMNS] (partition_key) [ INTERVAL (interval_expr) [ STORE IN (tablespace_name [, ... ] ) ] ] [ PARTITIONS integer ] ( partition_less_than_item [, ... ] )} |
        {RANGE [COLUMNS] (partition_key) [ INTERVAL (interval_expr) [ STORE IN (tablespace_name [, ... ] ) ] ] [ PARTITIONS integer ] ( partition_start_end_item [, ... ] )} |
        {LIST [COLUMNS] (partition_key) [ AUTOMATIC ] [ PARTITIONS integer ] ( PARTITION partition_name VALUES [IN] (list_values) [ 
ILM ADD POLICY ROW STORE COMPRESS ADVANCED ROW AFTER n { day | month | year } OF NO MODIFICATION [ ON ( EXPR )]] [ { COLVIEW | NOCOLVIEW } [ PRIORITY { HIGH | LOW | NONE } ] ][TABLESPACE [=] tablespace_name
][, ... ])} |
        {{ HASH | KEY } (partition_key) [ PARTITIONS integer ] ( PARTITION partition_name [ 
ILM ADD POLICY ROW STORE COMPRESS ADVANCED ROW AFTER n { day | month | year } OF NO MODIFICATION [ ON ( EXPR )]] [ { COLVIEW | NOCOLVIEW } [ PRIORITY { HIGH | LOW | NONE } ] ][TABLESPACE [=] tablespace_name
][, ... ])}
    } [ { ENABLE | DISABLE } ROW MOVEMENT ]; 
  • 其中table_option为:
    { COMMENT [ = ] 'string' |
      AUTO_INCREMENT [ = ] value |
      [ DEFAULT ] CHARACTER SET | CHARSET [ = ] default_charset |
      [ DEFAULT ] COLLATE [ = ] default_collation |
       ENGINE [ = ] { InnoDB | 'InnoDB' | "InnoDB" }  }
  • 其中htap_option为:
    { COLVIEW [ PRIORITY { HIGH | LOW | NONE } ] |
      NOCOLVIEW [ PRIORITY { HIGH | LOW | NONE } ]}
  • 列约束column_constraint:
    [ CONSTRAINT constraint_name ]
    { NOT NULL |
      NULL |
      CHECK ( expression ) |
      DEFAULT default_expr |
      ON UPDATE update_expr |
      GENERATED ALWAYS AS ( generation_expr ) [STORED] |
      GENERATED [ ALWAYS | BY DEFAULT [ ON NULL ] ] AS IDENTITY [ ( identity_options ) ] |
      AUTO_INCREMENT |
      COMMENT 'string' |
      COLVIEW |
      NOCOLVIEW |
      UNIQUE [KEY] index_parameters |
      PRIMARY KEY index_parameters |
      REFEREN CES  reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
        [ ON DELETE action ] [ ON UPDATE action ] }
    [ DEFERRABLE | NOT DEFERRABLE | INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
  • 表约束table_constraint:
    [ CONSTRAINT [ constraint_name ] ]
    { CHECK ( expression ) | 
      UNIQUE [ index_name ][ USING method ] ( { column_name [ ASC | DESC ] } [, ... ] ) index_parameters | 
      PRIMARY KEY [ USING method ] ( { column_name [ ASC | DESC ] } [, ... ] ) index_parameters |
      FOREIGN KEY [ index_name ] ( column_name [, ... ] ) REFERENCES reftable [ ( refcolumn [, ... ] ) ]
          [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE action ] [ ON UPDATE action ] }
    [ DEFERRABLE | NOT DEFERRABLE | INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
    { [ COMMENT 'string' ] [ ... ] }
  • like选项like_option:
    { INCLUDING | EXCLUDING } { DEFAULTS | GENERATED | CONSTRAINTS | INDEXES | STORAGE | COMMENTS | RELOPTIONS| UPDATE | IDENTITY | ILM | ALL }
  • 索引存储参数index_parameters:
    [ WITH ( {storage_parameter = value} [, ... ] ) ]
    [ USING INDEX TABLESPACE tablespace_name ]
support.huaweicloud.com/centralized-devg-v8-gaussdb/gaussdb-42-0575.html