SORTKEY

Important Notice: Migration of Documentation Website

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

Official Snowflake Snowconvert Documentation

For any immediate assistance or if you encounter any issues, please contact our support team at [email protected].

Thank you for your understanding.

Description

The keyword that specifies that the column is the sort key for the table. In Snowflake, SORTKEY from Redshift can be migrated to CLUSTER BY because both optimize data storage for query performance. CLUSTER BY in Snowflake organizes data on specified columns, similar to how SORTKEY orders data in Redshift.

Click here to navigate to the Amazon Redshift docs page for this syntax.

Grammar Syntax

[COMPOUND | INTERLEAVED ] SORTKEY ( column_name [,...]) | [ SORTKEY AUTO ]

Sample Source Patterns

Input Code:

IN -> Redshift_01.sql
CREATE TABLE table1 (
    col1 INTEGER,
    col2 VARCHAR,
    col3 INTEGER,
    col4 INTEGER
)
COMPOUND SORTKEY (col1, col3);

CREATE TABLE table2 (
    col1 INTEGER
)
INTERLEAVED SORTKEY (col1);

CREATE TABLE table3 (
    col1 INTEGER
)
SORTKEY AUTO;

Output Code:

OUT -> Redshift_01.sql
CREATE TABLE table1 (
    col1 INTEGER,
    col2 VARCHAR,
    col3 INTEGER,
    col4 INTEGER
)
--** SSC-FDM-RS0002 - THE PERFORMANCE OF THE CLUSTER BY MAY VARY COMPARED TO THE PERFORMANCE OF SORTKEY **
CLUSTER BY (col1, col3)
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "redshift",  "convertedOn": "09/17/2024" }}'
;

CREATE TABLE table2 (
    col1 INTEGER
)
--** SSC-FDM-RS0002 - THE PERFORMANCE OF THE CLUSTER BY MAY VARY COMPARED TO THE PERFORMANCE OF SORTKEY **
CLUSTER BY (col1)
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "redshift",  "convertedOn": "09/17/2024" }}'
;

CREATE TABLE table3 (
    col1 INTEGER
)
----** SSC-FDM-RS0001 - SORTKEY AUTO OPTION NOT SUPPORTED. DATA STORAGE IS AUTOMATICALLY HANDLED BY SNOWFLAKE. **
--SORTKEY AUTO
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "redshift",  "convertedOn": "09/17/2024" }}';
  1. SSC-FDM-RS0001: Option not supported. Data storage is automatically handled by Snowflake.

  2. SSC-FDM-RS0002: The performance of the CLUSTER BY may vary compared to the performance of Sortkey.

Last updated