SnowConvert AI – PostgreSQL – CREATE TABLE¶
Übersetzung von PostgreSql in Snowflake
Gilt für:¶
PostgreSQL
Greenplum
Netezza
Beschreibung¶
Erstellt eine neue Tabelle in PostgreSQL. Sie definieren eine Liste von Spalten, von denen jede Daten eines bestimmten Typs enthält. Die Person mit Eigentumsrechten an der Tabelle ist die Person, die den CREATE TABLE-Befehl absetzt.
Weitere Informationen dazu finden Sie in der Dokumentation zu CREATE TABLE.
Grammatikalische Syntax¶
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name ( [
{ column_name data_type [ STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT } ] [ COMPRESSION compression_method ] [ COLLATE collation ] [ column_constraint [ ... ] ]
| table_constraint
| LIKE source_table [ like_option ... ] }
[, ... ]
] )
[ INHERITS ( parent_table [, ... ] ) ]
[ PARTITION BY { RANGE | LIST | HASH } ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
[ USING method ]
[ WITH ( storage_parameter [= value] [, ... ] ) | WITHOUT OIDS ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE tablespace_name ]
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name
OF type_name [ (
{ column_name [ WITH OPTIONS ] [ column_constraint [ ... ] ]
| table_constraint }
[, ... ]
) ]
[ PARTITION BY { RANGE | LIST | HASH } ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
[ USING method ]
[ WITH ( storage_parameter [= value] [, ... ] ) | WITHOUT OIDS ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE tablespace_name ]
CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] table_name
PARTITION OF parent_table [ (
{ column_name [ WITH OPTIONS ] [ column_constraint [ ... ] ]
| table_constraint }
[, ... ]
) ] { FOR VALUES partition_bound_spec | DEFAULT }
[ PARTITION BY { RANGE | LIST | HASH } ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [, ... ] ) ]
[ USING method ]
[ WITH ( storage_parameter [= value] [, ... ] ) | WITHOUT OIDS ]
[ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
[ TABLESPACE tablespace_name ]
where column_constraint is:
[ CONSTRAINT constraint_name ]
{ NOT NULL |
NULL |
CHECK ( expression ) [ NO INHERIT ] |
DEFAULT default_expr |
GENERATED ALWAYS AS ( generation_expr ) STORED |
GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ] |
UNIQUE [ NULLS [ NOT ] DISTINCT ] index_parameters |
PRIMARY KEY index_parameters |
REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
[ ON DELETE referential_action ] [ ON UPDATE referential_action ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
and table_constraint is:
[ CONSTRAINT constraint_name ]
{ CHECK ( expression ) [ NO INHERIT ] |
UNIQUE [ NULLS [ NOT ] DISTINCT ] ( column_name [, ... ] ) index_parameters |
PRIMARY KEY ( column_name [, ... ] ) index_parameters |
EXCLUDE [ USING index_method ] ( exclude_element WITH operator [, ... ] ) index_parameters [ WHERE ( predicate ) ] |
FOREIGN KEY ( column_name [, ... ] ) REFERENCES reftable [ ( refcolumn [, ... ] ) ]
[ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ] [ ON DELETE referential_action ] [ ON UPDATE referential_action ] }
[ DEFERRABLE | NOT DEFERRABLE ] [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
and like_option is:
{ INCLUDING | EXCLUDING } { COMMENTS | COMPRESSION | CONSTRAINTS | DEFAULTS | GENERATED | IDENTITY | INDEXES | STATISTICS | STORAGE | ALL }
and partition_bound_spec is:
IN ( partition_bound_expr [, ...] ) |
FROM ( { partition_bound_expr | MINVALUE | MAXVALUE } [, ...] )
TO ( { partition_bound_expr | MINVALUE | MAXVALUE } [, ...] ) |
WITH ( MODULUS numeric_literal, REMAINDER numeric_literal )
index_parameters in UNIQUE, PRIMARY KEY, and EXCLUDE constraints are:
[ INCLUDE ( column_name [, ... ] ) ]
[ WITH ( storage_parameter [= value] [, ... ] ) ]
[ USING INDEX TABLESPACE tablespace_name ]
exclude_element in an EXCLUDE constraint is:
{ column_name | ( expression ) } [ COLLATE collation ] [ opclass [ ( opclass_parameter = value [, ... ] ) ] ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ]
referential_action in a FOREIGN KEY/REFERENCES constraint is:
{ NO ACTION | RESTRICT | CASCADE | SET NULL [ ( column_name [, ... ] ) ] | SET DEFAULT [ ( column_name [, ... ] ) ] }
Optionen für Tabellen¶
TEMPORARY | TEMP oder IF NOT EXISTS¶
Hinweis
Diese Syntax wird in Snowflake vollständig unterstützt.
GLOBAL | LOCAL¶
Bemerkung
Diese Syntax wird in Snowflake nicht benötigt.
Laut der PostgreSQL-Dokumentation sind GLOBAL | LOCAL für die Kompatibilität mit dem SQL-Standard vorhanden, haben jedoch keine Auswirkungen in PostgreSQL und sind veraltet. Aus diesem Grund entfernt SnowConvert AI diese Schlüsselwörter während des Migrationsprozesses.
Beispielquelle¶
Eingabecode:
PostgreSQL¶
CREATE GLOBAL TEMP TABLE TABLE1 (
COL1 integer
);
Ausgabecode:
Snowflake¶
CREATE TEMPORARY TABLE TABLE1 (
COL1 integer
)
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": { "major": 0, "minor": 0, "patch": "0" }, "attributes": { "component": "postgresql", "convertedOn": "05/09/2025", "domain": "no-domain-provided" }}';
UNLOGGED-TABLE¶
Bemerkung
Diese Syntax wird in Snowflake nicht benötigt.
UNLOGGED-Tabellen bieten einen erheblichen Geschwindigkeitsvorteil, da sie nicht in das Write-Ahead-Protokoll geschrieben werden. Snowflake unterstützt diese Funktionalität nicht, daher wird die UNLOGGED-Klausel auskommentiert.
Codebeispiel¶
Eingabecode:¶
Greenplum¶
CREATE UNLOGGED TABLE TABLE1 (
COL1 integer
);
Ausgabecode:¶
Snowflake¶
CREATE
-- --** SSC-FDM-PG0005 - UNLOGGED TABLE IS NOT SUPPORTED IN SNOWFLAKE, DATA WRITTEN MAY HAVE DIFFERENT PERFORMANCE. **
-- UNLOGGED
TABLE TABLE1 (
COL1 integer
)
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": { "major": 0, "minor": 0, "patch": "0" }, "attributes": { "component": "postgresql", "convertedOn": "05/09/2025", "domain": "no-domain-provided" }}';
Spaltenattribute¶
CHECK-Attribut¶
Gefahr
Diese Syntax wird in Snowflake nicht unterstützt.
Die CHECK-Klausel gibt einen Ausdruck an, der ein boolesches Ergebnis erzeugt, das neue oder aktualisierte Zeilen erfüllen müssen, damit eine Einfüge- oder Aktualisierungsoperation erfolgreich ist. Snowflake hat keine Äquivalenz mit dieser Klausel; SnowConvert AI fügt daher einen EWI hinzu. Dies wird als Einschränkung für CHECK-Attribute oder Tabellen angewendet.
Grammatikalische Syntax
CHECK ( <expression> )
Beispielquelle¶
Eingabecode:
PostgreSQL¶
CREATE TABLE table1 (
product_id INT PRIMARY KEY,
quantity INT CHECK (quantity >= 0)
);
Ausgabecode:
Snowflake¶
CREATE TABLE table1 (
product_id INT PRIMARY KEY,
quantity INT
!!!RESOLVE EWI!!! /*** SSC-EWI-0035 - CHECK STATEMENT NOT SUPPORTED ***/!!! CHECK (quantity >= 0)
)
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": { "major": 0, "minor": 0, "patch": "0" }, "attributes": { "component": "postgresql", "convertedOn": "05/09/2025", "domain": "no-domain-provided" }}';
GENERATED BY DEFAULT AS IDENTITY¶
Hinweis
Diese Syntax wird in Snowflake vollständig unterstützt.
Gibt an, dass die Spalte eine IDENTITY-Standardspalte ist und ermöglicht es Ihnen, der Spalte automatisch einen eindeutigen Wert zuzuweisen.
Grammatikalische Syntax
GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( <sequence_options> ) ]
Beispielquelle¶
Eingabecode:
PostgreSQL¶
CREATE TABLE table1 (
idValue INTEGER GENERATED ALWAYS AS IDENTITY)
Ausgabecode:
Snowflake¶
CREATE TABLE table1 (
idValue INTEGER IDENTITY(1, 1) ORDER
)
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": { "major": 0, "minor": 0, "patch": "0" }, "attributes": { "component": "postgresql", "convertedOn": "05/09/2025", "domain": "no-domain-provided" }}'
Tabelleneinschränkungen¶
Primary Key, Foreign Key und Unique¶
Warnung
Diese Syntax wird in Snowflake teilweise unterstützt.
SnowConvert AI behält die Einschränkungsdefinitionen bei; In Snowflake werden jedoch eindeutige Schlüssel, Primärschlüssel und Fremdschlüssel für die Dokumentation verwendet und erzwingen keine Einschränkungen oder Eindeutigkeit. Sie helfen bei der Beschreibung der Beziehungen zwischen den Tabellen, haben aber keinen Einfluss auf die Datenintegrität oder -leistung.
Attribute der Tabelle¶
LIKE-Option¶
Warnung
Diese Syntax wird in Snowflake teilweise unterstützt.
Die LIKE-Klausel gibt eine Tabelle an, aus der die neue Tabelle automatisch alle Spaltennamen, deren Datentypen und Nicht-Null-Einschränkungen kopiert. PostgreSQL unterstützt mehrere Optionen, während Snowflake dies nicht tut, sodass SnowConvert AI die Optionen entfernt.
Grammatikalische Syntax¶
LIKE source_table { INCLUDING | EXCLUDING }
{ AM | COMMENTS | CONSTRAINTS | DEFAULTS | ENCODING | GENERATED | IDENTITY | INDEXES | RELOPT | STATISTICS | STORAGE | ALL }
Beispielhafte Quellcode-Muster¶
Eingabecode:
PostgreSQL¶
CREATE TABLE source_table (
id INT,
name VARCHAR(255),
created_at TIMESTAMP,
status BOOLEAN
);
CREATE TABLE target_table_no_constraints (LIKE source_table INCLUDING DEFAULTS EXCLUDING CONSTRAINTS EXCLUDING INDEXES);
Ausgabecode:
Snowflake¶
CREATE TABLE source_table (
id INT,
name VARCHAR(255),
created_at TIMESTAMP,
status BOOLEAN
)
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": { "major": 0, "minor": 0, "patch": "0" }, "attributes": { "component": "postgresql", "convertedOn": "05/12/2025", "domain": "no-domain-provided" }}';
CREATE TABLE target_table_no_constraints LIKE source_table;
ON COMMIT¶
Warnung
Diese Syntax wird teilweise unterstützt.
Gibt das Verhalten der temporären Tabelle an, wenn ein Commit ausgeführt wird.
Grammatikalische Syntax¶
ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP }
Beispielhafte Quellcode-Muster¶
Eingabecode:¶
PostgreSQL¶
CREATE GLOBAL TEMPORARY TABLE temp_data_delete (
id INT,
data TEXT
) ON COMMIT DELETE ROWS;
Ausgabecode:¶
Snowflake¶
CREATE TEMPORARY TABLE temp_data_delete (
id INT,
data TEXT
)
----** SSC-FDM-0008 - ON COMMIT NOT SUPPORTED **
--ON COMMIT DELETE ROWS
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": { "major": 0, "minor": 0, "patch": "0" }, "attributes": { "component": "postgresql", "convertedOn": "05/12/2025", "domain": "no-domain-provided" }}';
PARTITION BY, USING, TABLESPACE und WITH¶
Bemerkung
Diese Syntax wird in Snowflake nicht benötigt.
Diese Klauseln in Snowflake sind unnötig, da sie den Datenspeicher automatisch verwalten, im Gegensatz zu PostgreSQL, wo die Einrichtung manuell erfolgen kann. Aus diesem Grund werden diese Klauseln bei der Migration entfernt.