SnowConvert: Postgres Issues¶

SSC-EWI-PG0003¶

Severity¶

Low

Description¶

PostgreSQL supports table inheritance, but this feature is not available in Snowflake. To learn more about PostgreSQL table inheritance, visit here.

Code Example¶

Input Code:¶

ALTER TABLE Table1
ADD CONSTRAINT const3 UNIQUE (zip);
Copy

Output Code:¶

!!!RESOLVE EWI!!! /*** SSC-EWI-PG0003 - TABLE INHERITANCE IS NOT SUPPORTED IN SNOWFLAKE. ***/!!!
ALTER TABLE Table1
ADD CONSTRAINT const3 UNIQUE (zip);
Copy

Recommendations¶

SSC-EWI-PG0013¶

Severity¶

Medium

Description¶

This error occurs when converting a Raise exception to a custom stored procedure.

Please note that raising exceptions outside an exception block is not supported in Snowflake. This is because Snowflake only allows the creation of new exceptions with literal messages, and does not support creating custom exceptions based on dynamic data.

Code Example¶

Input Code:¶

CREATE FUNCTION FunctionName1() RETURNS void
AS
$$
DECLARE
	v_var1        	character varying(50);
	v_var2        	character varying(50);
BEGIN
	v_var1 := 'exception1';
	v_var2 := 'exception2';
	RAISE EXCEPTION 'Exception %',v_var1;
    EXCEPTION
      WHEN OTHERS THEN
         RAISE EXCEPTION '%',v_var2;
         RETURN;
END;
$$
    LANGUAGE plpgsql NO SQL;
Copy

Output Code:¶

!!!RESOLVE EWI!!! /*** SSC-EWI-GP0002 - NON-RETURNING FUNCTION TRANSLATED TO STORED PROCEDURE ***/!!!
CREATE OR REPLACE PROCEDURE FunctionName1 () RETURNS STRING
    LANGUAGE SQL
AS
$$
DECLARE
	v_var1        	character varying(50);
	v_var2        	character varying(50);
BEGIN
	v_var1 := 'exception1';
	v_var2 := 'exception2';
	LET SC_RAISE_MESSAGE VARCHAR;
	SC_RAISE_MESSAGE := STRING_FORMAT_UDF('Exception %', array_construct(:v_var1));
	!!!RESOLVE EWI!!! /*** SSC-EWI-PG0013 - RAISE EXCEPTION TRANSLATED TO USER-DEFINED STORED PROCEDURE CALL. ***/!!!
	CALL RAISE_MESSAGE_UDF('EXCEPTION', :SC_RAISE_MESSAGE);
	RETURN 'SUCCESS';
    EXCEPTION
      WHEN OTHER THEN
		SC_RAISE_MESSAGE := STRING_FORMAT_UDF('%', array_construct(:v_var2));
		!!!RESOLVE EWI!!! /*** SSC-EWI-PG0013 - RAISE EXCEPTION TRANSLATED TO USER-DEFINED STORED PROCEDURE CALL. ***/!!!
		CALL RAISE_MESSAGE_UDF('EXCEPTION', :SC_RAISE_MESSAGE);
		RAISE;
         RETURN;
END;
$$;
Copy

The following User-Defined Functions (UDFs) are used during the transformation process:

CREATE OR REPLACE FUNCTION STRING_FORMAT_UDF(PATTERN VARCHAR, ARGS VARIANT)
RETURNS VARCHAR
LANGUAGE JAVASCRIPT
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "udf",  "convertedOn": "09/09/2024" }}'
AS
$$
	var placeholder_str = "{%}";
	var result = PATTERN.replace(/(?<!%)%(?!%)/g, placeholder_str).replace("%%","%");
	for (var i = 0; i < ARGS.length; i++)
	{
		result = result.replace(placeholder_str, ARGS[i]);
	}
	return result;
$$;
Copy
CREATE OR REPLACE PROCEDURE RAISE_MESSAGE_UDF(LEVEL VARCHAR, MESSAGE VARCHAR)
RETURNS VARCHAR
LANGUAGE SQL
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "udf",  "convertedOn": "09/09/2024" }}'
AS
$$
  BEGIN
    RETURN 'Logged message: ' || LEVEL || ' - ' || MESSAGE;
  END;
$$;
Copy

Recommendations¶

SSC-EWI-PG0006¶

Severity¶

Medium

Description¶

This error occurs when a variable in a FOR loop is referenced using a label name. Snowflake does not allow variables to be referenced using qualified names within FOR loops.

Code Example¶

Input Code:¶

CREATE OR REPLACE PROCEDURE procedure1(out result VARCHAR(100))
LANGUAGE plpgsql
AS $$
BEGIN
result := '<';
<<outer_loop>>
for i in 1..3 loop
  <<inner_loop>>
  for i in 4..6 loop
  result := result || '(' || outer_loop.i || ', ' || i || ')';
  end loop inner_loop;
end loop outer_loop;
result := result || '>';
END;
$$;
Copy

Output Code:¶

CREATE OR REPLACE PROCEDURE procedure1 (result VARCHAR(100))
RETURNS VARIANT
LANGUAGE SQL
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "redshift",  "convertedOn": "02/16/2025",  "domain": "test" }}'
AS $$
BEGIN
result := '<';
for i in 1 TO 3 loop
  for i in 4 TO 6 loop
  result := result || '(' ||
                             !!!RESOLVE EWI!!! /*** SSC-EWI-PG0006 - REFERENCE TO A VARIABLE USING THE LABEL IS NOT SUPPORTED BY SNOWFLAKE. ***/!!! outer_loop.i || ', ' || i || ')';
  end loop inner_loop;
end loop outer_loop;
result := result || '>';
  RETURN OBJECT_CONSTRUCT('result', :result);
END;
$$;
Copy

Recommendations¶

SSC-EWI-PG0002¶

Severity¶

Low

Description¶

The following index parameters in constraints are not compatible with Snowflake.

  • INCLUDE: Adds additional data or objects to the current operation

  • WITH: Specifies additional properties or conditions

  • USING INDEX TABLESPACE: Defines the tablespace where indexes will be stored

Code Example¶

Input Code:¶

CREATE TABLE Table1 (
    code        char(5),
    date_prod   date,
    CONSTRAINT production UNIQUE(date_prod) INCLUDE(code)
);

CREATE TABLE Table2 (
    name    varchar(40),
    UNIQUE(name) WITH (fillfactor=70)
);

CREATE TABLE Table3 (
    name    varchar(40),
    PRIMARY KEY(name) USING INDEX TABLESPACE tablespace_name
);
Copy

Output Code:¶

CREATE TABLE Table1 (
    code        char(5),
    date_prod   date,
    CONSTRAINT production UNIQUE(date_prod)
                                            !!!RESOLVE EWI!!! /*** SSC-EWI-PG0002 - INCLUDE PARAMETER NOT APPLICABLE. CONSTRAINT INDEX PARAMETERS ARE NOT SUPPORTED IN SNOWFLAKE. ***/!!! INCLUDE(code)
)
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "postgresql",  "convertedOn": "09/17/2024" }}';

CREATE TABLE Table2 (
    name    varchar(40),
    UNIQUE(name)
                 !!!RESOLVE EWI!!! /*** SSC-EWI-PG0002 - WITH PARAMETER NOT APPLICABLE. CONSTRAINT INDEX PARAMETERS ARE NOT SUPPORTED IN SNOWFLAKE. ***/!!! WITH (fillfactor=70)
)
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "postgresql",  "convertedOn": "09/17/2024" }}';

CREATE TABLE Table3 (
    name    varchar(40),
    PRIMARY KEY(name)
                      !!!RESOLVE EWI!!! /*** SSC-EWI-PG0002 - USING PARAMETER NOT APPLICABLE. CONSTRAINT INDEX PARAMETERS ARE NOT SUPPORTED IN SNOWFLAKE. ***/!!! USING INDEX TABLESPACE tablespace_name
)
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "postgresql",  "convertedOn": "09/17/2024" }}';
Copy

Recommendations¶

SSC-EWI-PG0012¶

Description¶

The NOT VALID option, which allows adding or modifying constraints without validating existing data, is not available in Snowflake. This PostgreSQL feature lets you add constraints while skipping the validation of existing records.

Code Example¶

Input Code:¶

ALTER TABLE Table1 *
ADD CONSTRAINT const UNIQUE (zip) NOT VALID;
Copy

Output Code:¶

ALTER TABLE Table1
ADD CONSTRAINT const UNIQUE (zip)
                                  !!!RESOLVE EWI!!! /*** SSC-EWI-PG0012 - NOT VALID CONSTRAINT OPTION IS NOT SUPPORTED BY SNOWFLAKE. ***/!!! NOT VALID;
Copy

Recommendations¶

SSC-EWI-PG0009¶

Severity¶

Low

Description¶

Comments can be added to different objects in the original code. However, since some of these objects don’t exist in Snowflake, the ability to add comments to them is not available. To prevent errors, the code that handles these unsupported comment scenarios has been disabled.

Code Example¶

Input Code:¶

COMMENT ON RULE rule_name on TABLE_NAME IS 'this is a comment';
Copy

Output Code:¶

!!!RESOLVE EWI!!! /*** SSC-EWI-PG0009 - COMMENT ON 'RULE' IS NOT SUPPORTED BY SNOWFLAKE. ***/!!!
COMMENT ON RULE rule_name on TABLE_NAME IS 'this is a comment';
Copy

Recommendations¶

SSC-EWI-PG0008¶

Severity¶

High

Description¶

The to_char function in Snowflake does not support the interval parameter when converting date and time data types to text format.

Code Example¶

Input Code:¶

SELECT to_char(interval '15h 2m 12s', 'HH24:MI:SS');
Copy

Output Code:¶

SELECT to_char(INTERVAL '15h, 2m, 12s', 'HH24:MI:SS') !!!RESOLVE EWI!!! /*** SSC-EWI-PG0008 - THE USE OF INTERVAL WITHIN TO_CHAR IS NOT SUPPORTED BY SNOWFLAKE. ***/!!!;
Copy

For additional information, please refer to

  • PostgreSQL to_char function documentation.

  • Snowflake to_char function documentation.

Recommendations¶

SSC-EWI-PG0005¶

Severity¶

Medium

Description¶

This error occurs because Snowflake has different date and numeric format requirements in certain functions compared to the source language.

The following date and time format elements might work differently in Snowflake compared to other databases:

Date / Time¶

Format ElementDescription
HHHour of day (01–12).
MSMillisecond (000–999).
USMicrosecond (000000–999999).
SSSS, SSSSSSeconds past midnight (0–86399).
Y,YYYYear (4 or more digits) with comma.
YYYLast 3 digits of year.
YLast digit of year.
IYYYISO 8601 week-numbering year(4 or more digits).
IYYLast 3 digits of ISO 8601 week-numbering year.
IYLast 2 digits of ISO 8601 week-numbering year.
ILast digit of ISO 8601 week-numbering year.
BC, bc, AD or adEra indicator (without periods).
B.C., b.c., A.D. or a.d.Era indicator (with periods).
MONTHFull upper case month name (blank-padded to 9 chars).
MonthFull capitalized month name (blank-padded to 9 chars).
monthFull lower case month name (blank-padded to 9 chars).
DAYFull upper case day name (blank-padded to 9 chars).
DayFull capitalized day name (blank-padded to 9 chars).
dayFull lower case day name (blank-padded to 9 chars).
DDDDay of year (001–366).
IDDDDay of ISO 8601 week-numbering year (001–371; day 1 of the year is Monday of the first ISO week).
DDay of the week, Sunday (1) to Saturday (7).
IDISO 8601 day of the week, Monday (1) to Sunday (7).
WWeek of month (1–5) (the first week starts on the first day of the month).
WWWeek number of year (1–53) (the first week starts on the first day of the year).
IWWeek number of ISO 8601 week-numbering year (01–53; the first Thursday of the year is in week 1).
CCCentury (2 digits) (the twenty-first century starts on 2001-01-01).
JJulian Date.
QQuarter.
RMMonth in upper case Roman numerals (I–XII; I=January).
rmMonth in lower case Roman numerals (i–xii; i=January).
TZUpper case time-zone abbreviation (only supported in to_char).
tzLower case time-zone abbreviation (only supported in to_char).
TZHTime-zone hours.
TZMTime-zone minutes.
OFTime-zone offset from UTC (only supported in to_char).
FM prefixFill mode (suppress leading zeroes and padding blanks).
TH suffixUpper case ordinal number suffix.
th suffixLower case ordinal number suffix.
FX prefixFixed format global option (see usage notes).
TM prefixTranslation mode (use localized day and month names based on lc_time).
SP suffixSpell mode.

For additional details, please see the PostgreSQL Date/Time formats documentation.

The TO_CHAR function transformation supports most format elements. For a complete list of supported format elements and their corresponding mappings, please see the Translation specification

Numeric ¶

Pattern

Description

PR

negative value in angle brackets

RN

Roman numeral (input between 1 and 3999)

TH or th

ordinal number suffix

V

shift specified number of digits (see notes)

EEEE

exponent for scientific notation

For additional details, please see the PostgreSQL Numeric formats documentation.

Code Example¶

Input Code:¶

SELECT
   DATE_TRUNC('decade', TIMESTAMP '2017-03-17 02:09:30'),
   DATE_TRUNC('century', TIMESTAMP '2017-03-17 02:09:30'),
   DATE_TRUNC('millennium', TIMESTAMP '2017-03-17 02:09:30');
Copy

Output Code:¶

SELECT
      !!!RESOLVE EWI!!! /*** SSC-EWI-PG0005 - DECADE FORMAT IS NOT SUPPORTED IN SNOWFLAKE. ***/!!!
      DATE_TRUNC('decade', TIMESTAMP '2017-03-17 02:09:30'),
      !!!RESOLVE EWI!!! /*** SSC-EWI-PG0005 - CENTURY FORMAT IS NOT SUPPORTED IN SNOWFLAKE. ***/!!!
      DATE_TRUNC('century', TIMESTAMP '2017-03-17 02:09:30'),
      !!!RESOLVE EWI!!! /*** SSC-EWI-PG0005 - MILLENNIUM FORMAT IS NOT SUPPORTED IN SNOWFLAKE. ***/!!!
      DATE_TRUNC('millennium', TIMESTAMP '2017-03-17 02:09:30');
Copy

Recommendations¶

SSC-EWI-PG0015¶

Severity¶

Medium

Description¶

In PostgreSQL, you can use a FETCH statement to display fetched row values directly in the console without using an INTO clause. However, when using Snowflake, the FETCH statement must include an INTO clause to specify the variables where the fetched values will be stored.

When SnowConvert encounters a FETCH statement without an INTO clause, it will generate an Error, Warning, or Information (EWI) message to inform users that this FETCH syntax is not supported.

Code Example¶

Input Code:¶

FETCH PRIOR FROM cursor1;
Copy

Output Code:¶

!!!RESOLVE EWI!!! /*** SSC-EWI-PG0015 - FETCH CURSOR WITHOUT TARGET VARIABLES IS NOT SUPPORTED IN SNOWFLAKE ***/!!!
FETCH PRIOR FROM cursor1;
Copy

Recommendations¶

SSC-EWI-PG0001¶

Severity¶

Medium

Description¶

This error occurs because SnowConvert does not support the age() function.

Code Example¶

Input Code:¶

SELECT
   age(date1::date, date2::date)
FROM
   Table1;
Copy

Output Code:¶

SELECT
      !!!RESOLVE EWI!!! /*** SSC-EWI-PG0001 - AGE IS NOT SUPPORTED ON SNOWFLAKE. ***/!!!
      age(date1::date, date2::date)
FROM
      Table1;
Copy

Recommendations¶

  • The Datediff function helps calculate time differences between dates. While it can be used to get specific date ranges, you’ll need to customize the implementation for each use case. For detailed information, see the Snowflake documentation on Datediff.

  • For additional assistance, contact us at snowconvert-support@snowflake.com

SSC-EWI-PG0011¶

Severity¶

Low

Description¶

PostgreSQL sequence statements have certain options that are not compatible with Snowflake’s functionality.

The following features are not currently supported:

  • Unlogged: Sequences are not written to the Write-Ahead Log (WAL)

  • AS <data_type>: Specifies the data type of the sequence

  • MinValue: Sets the minimum value for the sequence

  • MaxValue: Sets the maximum value for the sequence

  • No MinValue: Removes the minimum value limit

  • No MaxValue: Removes the maximum value limit

  • Cache: Specifies how many sequence numbers to pre-allocate in memory

  • Cycle: Allows the sequence to restart when reaching its limit

  • Owner By: Assigns ownership of the sequence to a specific user

Code Example¶

Input code:¶

CREATE UNLOGGED SEQUENCE sequence_name;
Copy

Output code:¶

--** SSC-FDM-PG0009 - THE SEQUENCE NEXTVAL PROPERTY SNOWFLAKE DOES NOT GUARANTEE GENERATING SEQUENCE NUMBERS WITHOUT GAPS. **
CREATE UNLOGGED !!!RESOLVE EWI!!! /*** SSC-EWI-PG0011 - 'UNLOGGED' IS NOT SUPPORTED BY SNOWFLAKE. ***/!!! SEQUENCE sequence_name;
Copy

Recommendations¶

SSC-EWI-PG0010¶

Severity¶

Low

Description¶

When PostgreSQL creates a temporary sequence, it exists only during the current session and is automatically removed when the session ends. Since Snowflake does not support temporary sequences, SC converts them to regular sequences. This may cause naming conflicts if a sequence with the same name already exists in Snowflake, resulting in an error.

Code Example¶

Input code:¶

CREATE TEMPORARY SEQUENCE sequence1;
CREATE TEMP SEQUENCE sequence2;
Copy

Output code:¶

--** SSC-FDM-PG0009 - THE SEQUENCE NEXTVAL PROPERTY SNOWFLAKE DOES NOT GUARANTEE GENERATING SEQUENCE NUMBERS WITHOUT GAPS. **
CREATE TEMPORARY !!!RESOLVE EWI!!! /*** SSC-EWI-PG0010 - CREATE TEMPORARY SEQUENCE IS NOT SUPPORTED BY SNOWFLAKE. ***/!!! SEQUENCE sequence1;


--** SSC-FDM-PG0009 - THE SEQUENCE NEXTVAL PROPERTY SNOWFLAKE DOES NOT GUARANTEE GENERATING SEQUENCE NUMBERS WITHOUT GAPS. **
 CREATE TEMP !!!RESOLVE EWI!!! /*** SSC-EWI-PG0010 - CREATE TEMPORARY SEQUENCE IS NOT SUPPORTED BY SNOWFLAKE. ***/!!! SEQUENCE sequence2;
Copy

Recommendations¶

  • If you encounter issues during creation, try renaming the sequence to prevent naming conflicts.

  • For additional assistance, please contact us at snowconvert-support@snowflake.com.

SSC-EWI-PG0004¶

Severity¶

Medium

Description¶

The EXCLUDE constraint, which is available in PostgreSQL, is not currently supported in Snowflake.

Code Example¶

Input Code:¶

CREATE TABLE Table1 (
    id      int,
    EXCLUDE USING gist (id WITH &&)
);
Copy

Output Code:¶

CREATE TABLE Table1 (
    id      int,
    !!!RESOLVE EWI!!! /*** SSC-EWI-PG0004 - EXCLUDE CONSTRAINT IS NOT SUPPORTED IN SNOWFLAKE. ***/!!!
    EXCLUDE USING gist (id WITH &&)
)
COMMENT = '{ "origin": "sf_sc", "name": "snowconvert", "version": {  "major": 0,  "minor": 0,  "patch": "0" }, "attributes": {  "component": "postgresql",  "convertedOn": "09/17/2024" }}';
Copy

Recommendations¶

SSC-EWI-PG0014¶

Severity¶

Moderate

Description¶

In Snowflake, the FETCH cursor statement retrieves the next row from a cursor. When converting code, SnowConvert transforms cursor navigation commands that are equivalent to FETCH NEXT since they perform the same function in Snowflake.

  • FETCH NEXT: Retrieves the next row from the result set

  • FETCH FORWARD: Moves forward to retrieve the next row

  • FETCH RELATIVE 1: Moves one row forward from the current position

  • FETCH (without direction): Uses the default forward movement to get the next row

Any orientation other than the default is not supported. If used, the FETCH statement will be marked with an Error, Warning, or Information (EWI) message.

Code Example¶

Input Code:¶

CREATE OR REPLACE PROCEDURE cursor_test()
AS $$
BEGIN
   FETCH FORWARD FROM cursor1 INTO my_var;
   FETCH FIRST FROM cursor1 INTO my_var;
   FETCH LAST FROM cursor1 INTO my_var;
END;
$$;
Copy

Output Code:¶

CREATE OR REPLACE PROCEDURE cursor_test ()
RETURNS VARCHAR
AS $$
BEGIN
   FETCH
   	cursor1 INTO my_var;
   !!!RESOLVE EWI!!! /*** SSC-EWI-PG0014 - SNOWFLAKE SCRIPTING CURSORS DO NOT SUPPORT FETCH ORIENTATION. ***/!!!
   FETCH FIRST FROM cursor1 INTO my_var;
   !!!RESOLVE EWI!!! /*** SSC-EWI-PG0014 - SNOWFLAKE SCRIPTING CURSORS DO NOT SUPPORT FETCH ORIENTATION. ***/!!!
   FETCH LAST FROM cursor1 INTO my_var;
END;
$$;
Copy

Recommendations¶