This document contains the builtin functions as specified by the SQL standard, as well as a section on extended builtins which are not in the SQL spec, but are common amongst SQL implementations.
Identifier | Names | Signatures | Description |
---|---|---|---|
COUNT_STAR |
count |
|
Returns the number of rows |
COUNT |
count |
|
Returns the number of rows for which x is not null |
SUM |
sum |
T — any numeric, interval |
Sum of x for all non-null input values |
MIN |
min |
T — any numeric, string, date/time |
Minimum of x for all non-null input values |
MAX |
max |
T — any numeric, string, date/time |
Maximum of x for all non-null input values |
EVERY |
every |
|
Returns true if all x are true |
ANY |
any |
|
?? |
SOME |
some |
|
?? |
STDDEV_POP |
stddev_pop, stddev_population |
T — smallint, int, bigint, real, double precision, or numeric |
Population standard deviation |
STDDEV_SAMP |
stddev_samp, stddev_sample, stddev |
T — smallint, int, bigint, real, double precision, or numeric |
Sample standard deviation |
VAR_POP |
var_pop, var_population |
T — smallint, int, bigint, real, double precision, or numeric |
Population variance |
VAR_SAMP |
var_samp, var_sample, variance |
T — smallint, int, bigint, real, double precision, or numeric |
Sample variance |
COVAR_POP |
covar_pop, covar_population |
|
Population covariance |
COVAR_SAMP |
covar_samp, covar_sample, covar |
|
Sample covariance |
CORR |
corr |
|
Correlation coefficient |
All arguments must be comparable types T as defined by the SQL specification subclause 4.12.
Identifier | Names | Signatures | Description |
---|---|---|---|
LT |
< |
|
Returns true if x is less than y |
LTE |
<= |
|
Returns true if x is less than or equal to y |
GT |
> |
|
Returns true if x is greater than y |
GTE |
>= |
|
Returns true if x is greater than or equal to y |
EQ |
= |
|
Returns true if x is equal to y |
NEQ |
!=, <> |
|
Returns true if x is not equal to y |
Identifier | Names | Signatures | Description |
---|---|---|---|
PLUS |
+ |
|
Addition of two numeric types T and S |
MINUS |
- |
|
Subtraction of two numeric types T and S |
MULT |
* |
|
Multiplication of two numeric types T and S |
DIV |
/ |
|
Integer division of two numeric types T and S |
ABS |
abs |
|
Returns the absolute value of x |
MOD |
mod |
|
Returns x modulo y |
CEILING |
ceil, ceiling |
|
Returns the smallest integer greater than or equal to x |
FLOOR |
floor |
|
Returns the largest integer less than or equal to x |
SQRT |
sqrt |
T — double or numeric |
Square root |
EXP |
exp |
T — double or numeric |
Exponential function e^x |
POWER |
power |
|
Returns x raised to the power of y |
LN |
ln |
T — double or numeric |
Natural log of x |
Identifier | Names | Signatures | Description |
---|---|---|---|
CONCAT |
|| |
|
Concatenates x and y Special form: x || y |
LOWER |
lower |
|
Converts x to lowercase |
UPPER |
upper |
|
Converts x to uppercase |
BIT_LENGTH |
bit_length |
|
Returns the number of bits in x |
CHAR_LENGTH |
char_length, character_length |
|
Returns the number of characters in x |
OCTET_LENGTH |
octet_length |
|
Returns the number of bytes in x |
SUBSTRING |
substring |
|
Returns the substring of s starting at start index for len characters. If start is not specified, 0 is the default. If len is not specified, the substring will span to the end of s. Special form:
|
SUBSTRING_PATTERN |
substring |
|
Extracts the first substring matching SQL regular expression Special form:
|
TRIM |
trim |
|
Trims the characters y (a space by default) from either the start, end, or both ends of x. Special form:
|
POSITION |
position |
|
Returns first starting index of y within x, or zero if it’s not present. Special form:
|
OVERLAY |
overlay |
|
Replaces the content x with y starting at start and extending for count or the length of y. Overlay has the special form:
|
-- Postgres regression functions 9.58
-- Trino approximate aggregations
-- https://trino.io/docs/current/functions/aggregate.html#approximate-aggregate-functions
x % y -- MOD(x, y)
x ^ y -- POWER(x,y)
x & y -- bitwise AND
x | y -- bitwise OR
~x -- bitwise NOT
x << y -- bitwise shift left
x >> y -- bitwise shift right
SIGN(x) -- sign
ROUND(x) -- round to nearest integer
ROUND(x, d) -- round to d decimal places
TRUNC(x) -- truncate toward 0
TRUNC(x, d) -- truncate to d decimal places
LOG(b, x) -- log x base b
LOG(x) -- log x base 10
GREATEST(collection) -- returns the largest in collection
LEAST(collection) -- returns the smallest in collection
SIN(x) -- sine
COS(x) -- cosine
TAN(x) -- tangent
COT(x) -- cotangent
ASIN(x) -- arc sine
ACOS(x) -- arc cosine
ATAN(x) -- arc tangent
PI() -- pi constant
TRUNC(x) -- truncate to integer
ASCII(x) -- convert character x to ASCII
CHR(x) -- convert ASCII x to character
POSITION(x IN y) -- alias for SUBSTRING_REGEX(x IN y FROM 0)
LENGTH(x) -- number of characters in string
REPLACE(x, y, z) -- replace all occurrences of y in x to z
REVERSE(x) -- reverse x
TRIM(x) -- alias for TRIM(BOTH ' ' FROM x)