SnowConvert AI - PostgreSQL - Built-in functions¶
Applies to¶
PostgreSQL
Greenplum
Netezza
Note
For more information about built-in functions and their Snowflake equivalents, also see Common built-in functions.
Aggregate Functions¶
Aggregate functions compute a single result value from a set of input values. (PostgreSQL Language Reference Aggregate Functions (https://www.postgresql.org/docs/12/functions-aggregate.html)).
PostgreSQL |
Snowflake |
---|---|
AVG (https://www.postgresql.org/docs/12/functions-aggregate.html) |
Notes: PostgreSQL and Snowflake may show different precision/decimals due to data type rounding/formatting. |
COUNT (https://www.postgresql.org/docs/12/functions-aggregate.html) |
|
MAX (https://www.postgresql.org/docs/12/functions-aggregate.html) |
|
MEDIAN (https://techdocs.broadcom.com/us/en/vmware-tanzu/data-solutions/tanzu-greenplum/7/greenplum-database/ref_guide-function-summary.html#topic31) |
Notes: Snowflake does not allow the use of date types, while PostgreSQL does. (See SSC-FDM-PG0013). |
MIN (https://www.postgresql.org/docs/12/functions-aggregate.html) |
|
PERCENTILE_CONT (https://www.postgresql.org/docs/9.4/functions-aggregate.html#FUNCTIONS-ORDEREDSET-TABLE) |
|
STDDEV/STDDEV_SAMP (https://www.postgresql.org/docs/12/functions-aggregate.html) (expression) |
STDDEV/STDDEV_SAMP (expression) |
STDDEV_POP (https://www.postgresql.org/docs/12/functions-aggregate.html) (expression) |
STDDEV_POP (expression) |
SUM (https://www.postgresql.org/docs/12/functions-aggregate.html) |
|
VARIANCE/VAR_SAMP (https://www.postgresql.org/docs/12/functions-aggregate.html) (expression) |
VARIANCE/VAR_SAMP (expression) |
VAR_POP (https://www.postgresql.org/docs/12/functions-aggregate.html) (expression) |
VAR_POP (expression) |
Conditional expressions¶
PostgreSQL |
Snowflake |
---|---|
COALESCE (https://www.postgresql.org/docs/12/functions-conditional.html) ( value [, …] ) |
COALESCE ( expression, expression, … ) |
GREATEST (https://www.postgresql.org/docs/12/functions-conditional.html) ( value [, …] ) |
GREATEST_IGNORE_NULLS ( <expr1> [, <expr2> … ] ) |
LEAST (https://www.postgresql.org/docs/12/functions-conditional.html) ( value [, …] ) |
LEAST_IGNORE_NULLS ( <expr1> [, <expr2> … ]) |
NULLIF (https://www.postgresql.org/docs/12/functions-conditional.html) |
NULLIF |
Data type formatting functions¶
Data type formatting functions provide an easy way to convert values from one data type to another. For each of these functions, the first argument is always the value to be formatted and the second argument contains the template for the new format. (PostgreSQL Language Reference Data type formatting functions (https://www.postgresql.org/docs/12/functions-formatting.html)).
PostgreSQL |
Snowflake |
---|---|
TO_CHAR (https://www.postgresql.org/docs/12/functions-formatting.html) |
Notes: Snowflake’s support for this function is partial (see SSC-EWI-PG0005). |
TO_DATE (https://www.postgresql.org/docs/12/functions-formatting.html) |
Notes: Snowflake’s |
Date and time functions¶
PostgreSQL |
Snowflake |
---|---|
AT TIME ZONE ‘timezone’ (https://www.postgresql.org/docs/12/functions-datetime.html#FUNCTIONS-DATETIME-ZONECONVERT) |
CONVERT_TIMEZONE ( <source_tz> , <target_tz> , <source_timestamp_ntz> ) CONVERT_TIMEZONE ( <target_tz> , <source_timestamp> ) Notes: PostgreSQL defaults to UTC; the Snowflake function requires explicit UTC specification. Therefore, it will be added as the target timezone. |
CURRENT_DATE (https://www.postgresql.org/docs/8.2/functions-datetime.html) |
|
DATE_PART/PGDATE_PART (https://www.postgresql.org/docs/12/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT) |
Notes: this function is partially supported by Snowflake. (See SSC-EWI-PGOOO5). |
DATE_TRUNC (https://www.postgresql.org/docs/12/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT) |
Notes: Invalid date part formats are translated to Snowflake-compatible formats. |
TO_TIMESTAMP (https://www.postgresql.org/docs/12/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT) |
|
EXTRACT (https://www.postgresql.org/docs/current/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT) |
EXTRACT |
TIMEZONE (https://www.postgresql.org/docs/16/functions-datetime.html#FUNCTIONS-DATETIME-ZONECONVERT) |
Note
PostgreSQL timestamps default to microsecond precision (6 digits); Snowflake defaults to nanosecond precision (9 digits). Adjust precision as needed using ALTER SESSION (e.g., ALTER SESSION SET TIMESTAMP_OUTPUT_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF2';
). Precision loss may occur depending on the data type used.
Since some formats are incompatible with Snowflake, adjusting the account parameters DATE_INPUT_FORMAT or TIME_INPUT_FORMAT might maintain functional equivalence between platforms.
JSON Functions¶
PostgreSQL |
Snowflake |
---|---|
JSON_EXTRACT_PATH_TEXT (https://www.postgresql.org/docs/9.3/functions-json.html) |
Notes:
|
Math functions¶
PostgreSQL |
Snowflake |
---|---|
ACOS (https://www.postgresql.org/docs/12/functions-math.html) |
|
ASIN (https://www.postgresql.org/docs/12/functions-math.html) |
|
ATAN (https://www.postgresql.org/docs/12/functions-math.html) |
|
ATAN2 (https://www.postgresql.org/docs/12/functions-math.html) |
|
CBRT (https://www.postgresql.org/docs/12/functions-math.html) |
|
CEIL/CEILING (https://www.postgresql.org/docs/12/functions-math.html) |
|
COS (https://www.postgresql.org/docs/12/functions-math.html) |
|
COT (https://www.postgresql.org/docs/12/functions-math.html) |
|
DEGREES (https://www.postgresql.org/docs/12/functions-math.html) |
|
LN (https://www.postgresql.org/docs/12/functions-math.html) |
|
EXP (https://www.postgresql.org/docs/12/functions-math.html) |
|
FLOOR (https://www.postgresql.org/docs/12/functions-math.html) |
|
LOG (https://www.postgresql.org/docs/12/functions-math.html) |
|
MOD (https://www.postgresql.org/docs/12/functions-math.html) |
|
PI (https://www.postgresql.org/docs/12/functions-math.html) |
|
POWER/POW (https://www.postgresql.org/docs/12/functions-math.html) |
|
RADIANS (https://www.postgresql.org/docs/12/functions-math.html) |
|
RANDOM (https://www.postgresql.org/docs/12/functions-math.html) |
|
ROUND (https://www.postgresql.org/docs/12/functions-math.html) |
|
SIN (https://www.postgresql.org/docs/12/functions-math.html) |
|
SIGN (https://www.postgresql.org/docs/12/functions-math.html) |
|
SQRT (https://www.postgresql.org/docs/12/functions-math.html) |
|
TAN (https://www.postgresql.org/docs/12/functions-math.html) |
|
TRUNC (https://www.postgresql.org/docs/12/functions-math.html) |
Note
PostgreSQL and Snowflake results may differ in scale.
String functions¶
String functions process and manipulate character strings or expressions that evaluate to character strings. (PostgreSQL Language Reference String functions (https://www.postgresql.org/docs/12/functions-string.html)).
PostgreSQL |
Snowflake |
---|---|
ASCII (https://www.postgresql.org/docs/12/functions-string.html) |
|
BTRIM (https://www.postgresql.org/docs/12/functions-string.html) |
|
CHAR_LENGTH (https://www.postgresql.org/docs/12/functions-string.html) |
|
CHARACTER_LENGTH (https://www.postgresql.org/docs/12/functions-string.html) |
|
CHR (https://www.postgresql.org/docs/9.1/functions-string.html) |
|
CONCAT (https://www.postgresql.org/docs/12/functions-string.html) |
|
INITCAP (https://www.postgresql.org/docs/12/functions-string.html) |
|
LEFT/RIGHT (https://www.postgresql.org/docs/12/functions-string.html) |
|
LOWER (https://www.postgresql.org/docs/12/functions-string.html) |
|
OCTET_LENGTH (https://www.postgresql.org/docs/12/functions-string.html) |
Notes: the results may vary between platforms (See SSC-FDM-PG0013). |
QUOTE_IDENT (https://www.postgresql.org/docs/12/functions-string.html) (string) |
CONCAT (‘”’, string, ‘”’) |
REGEXP_REPLACE (https://www.postgresql.org/docs/12/functions-string.html) |
Notes: This function includes a |
REPEAT (https://www.postgresql.org/docs/12/functions-string.html) |
|
REPLACE (https://www.postgresql.org/docs/12/functions-string.html) |
|
REVERSE (https://www.postgresql.org/docs/12/functions-string.html) |
|
SPLIT_PART (https://www.postgresql.org/docs/12/functions-string.html) |
Notes: Snowflake and PostgreSQL handle SPLIT_PART differently with case-insensitive collations. |
STRPOS (https://www.postgresql.org/docs/12/functions-string.html) (string, substring ) |
POSITION ( <expr1> IN <expr> ) |
SUBSTRING (https://www.postgresql.org/docs/12/functions-string.html) |
Notes: Snowflake partially supports this function. PostgreSQL’s |
TRANSLATE (https://www.postgresql.org/docs/12/functions-string.html) |
|
TRIM (https://www.postgresql.org/docs/12/functions-string.html) |
Notes: PostgreSQL uses keywords (BOTH, LEADING, TRAILING) for trim; Snowflake uses TRIM, LTRIM, RTRIM. |
UPPER (https://www.postgresql.org/docs/12/functions-string.html) |
Window functions¶
PostgreSQL |
Snowflake |
---|---|
AVG (https://www.postgresql.org/docs/9.4/functions-aggregate.html) |
Notes: AVG rounding/formatting can vary by data type between PostgreSQL and Snowflake. |
COUNT (https://www.postgresql.org/docs/9.4/functions-aggregate.html) |
|
DENSE_RANK (https://www.postgresql.org/docs/current/functions-window.html) |
Notes: ORDER BY is mandatory in Snowflake; missing clauses are replaced with |
FIRST_VALUE (https://www.postgresql.org/docs/current/functions-window.html) |
Notes: Snowflake needs ORDER BY; missing clauses get |
LAG (https://www.postgresql.org/docs/current/functions-window.html) |
|
LAST_VALUE (https://www.postgresql.org/docs/current/functions-window.html) |
Notes: Snowflake needs ORDER BY; missing clauses get |
LEAD (https://www.postgresql.org/docs/current/functions-window.html) |
Notes: PostgreSQL allows constant or expression offsets; Snowflake allows only constant offsets. |
NTH_VALUE (https://www.postgresql.org/docs/current/functions-window.html) |
Notes: ORDER BY is mandatory in Snowflake; missing clauses are replaced with |
NTILE (https://www.postgresql.org/docs/current/functions-window.html) |
Notes: ORDER BY is mandatory in Snowflake; missing clauses are replaced with |
PERCENT_RANK (https://www.postgresql.org/docs/current/functions-window.html) |
Notes: ORDER BY is mandatory in Snowflake; missing clauses are replaced with |
PERCENTILE_CONT (https://www.postgresql.org/docs/9.4/functions-aggregate.html) |
Notes: Rounding varies between platforms. |
PERCENTILE_DISC (https://www.postgresql.org/docs/9.4/functions-aggregate.html) |
|
RANK (https://www.postgresql.org/docs/current/functions-window.html) |
|
ROW_NUMBER (https://www.postgresql.org/docs/current/functions-window.html) |
Notes: ORDER BY is mandatory in Snowflake; missing clauses are replaced with |