SnowConvert AI - PostgreSQL - CREATE TABLE¶
Translation from PostgreSQL to Snowflake
Applies to¶
PostgreSQL
Greenplum
Netezza
Description¶
Creates a new table in PostgreSQL. You define a list of columns, each of which holds data of a distinct type. The owner of the table is the issuer of the CREATE TABLE command.
For more information, please refer to CREATE TABLE documentation.
Grammar Syntax¶
Tables Options¶
TEMPORARY | TEMP, or IF NOT EXISTS¶
Hint
This syntax is fully supported in Snowflake.
GLOBAL | LOCAL¶
Note
This syntax is not needed in Snowflake.
According to PostgreSQL’s documentation, GLOBAL | LOCAL are present for SQL Standard compatibility, but have no effect in PostgreSQL and are deprecated. For that reason, SnowConvert AI will remove these keyworks during the migration process.
Sample Source¶
Input Code:
PostgreSQL¶
Output Code:
Snowflake¶
UNLOGGED TABLE¶
Note
This syntax is not needed in Snowflake.
UNLOGGED tables offer a significant speed advantage because they are not written to the write-ahead log. Snowflake doesn’t support this functionality, so the UNLOGGED clause will be commented out.
Code Example¶
Input Code:¶
Greenplum¶
Output Code:¶
Snowflake¶
Column Attributes¶
CHECK Attribute¶
Hint
This syntax is supported in Snowflake for deterministic, scalar expressions.
The CHECK clause specifies an expression producing a Boolean result that new or updated rows must satisfy for an insert or update operation to succeed. Snowflake supports CHECK constraints with deterministic, scalar expressions. Unsupported expressions (UDFs, non-deterministic functions) are flagged with SSC-EWI-0116.
Supported:
Basic CHECK constraints with scalar, deterministic expressions
Column-level and table-level CHECK constraints
Named and unnamed constraints
Unsupported (flagged with SSC-EWI-0116):
User-defined functions (UDFs)
Non-deterministic built-in functions
Context-dependent functions (e.g.,
CURRENT_TIMESTAMP,CURRENT_USER,NOW())Subqueries
Grammar Syntax
Sample Source¶
Example 1: Basic CHECK Constraint (Supported)¶
Input Code:
PostgreSQL¶
Output Code:
Snowflake¶
Example 2: Named Table-Level CHECK Constraint¶
Input Code:
PostgreSQL¶
Output Code:
Snowflake¶
GENERATED BY DEFAULT AS IDENTITY¶
Hint
This syntax is fully supported in Snowflake.
Specifies that the column is a default IDENTITY column and enables you to assign a unique value to the column automatically.
Grammar Syntax
Sample Source¶
Input Code:
PostgreSQL¶
Output Code:
Snowflake¶
Table Constraints¶
Primary Key, Foreign Key, and Unique¶
Warning
This syntax is partially supported in Snowflake.
SnowConvert AI keeps the constraint definitions; however, in Snowflake, unique, primary, and foreign keys are used for documentation and do not enforce constraints or uniqueness. They help describe table relationships but don’t impact data integrity or performance.
Table Attributes¶
LIKE option¶
Warning
This syntax is partially supported in Snowflake.
The LIKE clause specifies a table from which the new table automatically copies all column names, their data types, and their not-null constraints. PostgreSQL supports several options, while Snowflake does not so that SnowConvert AI will remove the options like.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:
PostgreSQL¶
Output Code:
Snowflake¶
ON COMMIT¶
Warning
This syntax is partially supported.
Specifies the behaviour of the temporary table when a commit is done.
Grammar Syntax¶
Sample Source Patterns¶
Input Code:¶
PostgreSQL¶
Output Code:¶
Snowflake¶
PARTITION BY, USING, TABLESPACE, and WITH¶
Note
This syntax is not needed in Snowflake.
These clauses in Snowflake are unnecessary because they automatically handle the data storage, unlike PostgreSQL, which could be set up manually. For this reason, these clauses are removed during migration.