Skip to main content

Functions

Functions grouped by what they work on.

Text​

Case and length​

NameWhat it does
LOWERA string in lower case.
UPPERA string in upper case.
INITCAPA string with the first letter of each word in upper case.
LENGTHThe number of characters in a string.

Find​

NameWhat it does
STRPOSThe position of a substring in a string.
POSITIONThe position of a substring in a string, standard form.
STARTS_WITHWhether a string begins with a prefix.
REGEXP_LIKEWhether a string matches a regular expression.

Take part of a string​

NameWhat it does
SUBSTRINGPart of a string, by start position and length.
LEFTThe first characters of a string.
RIGHTThe last characters of a string.
SPLIT_PARTOne part of a string split on a delimiter.

Change a string​

NameWhat it does
REPLACEA string with every occurrence of one substring replaced by another.
REGEXP_REPLACEA string with matches of a regular expression replaced.
TRIMA string with characters removed from both ends.
LTRIMA string with characters removed from the start.
RTRIMA string with characters removed from the end.
LPADA string padded on the left to a length.
RPADA string padded on the right to a length.
REVERSEA string with its characters in reverse order.
CONCATStrings joined end to end, skipping NULLs.
CONCAT_WSStrings joined with a separator, skipping NULLs.

Split into rows​

NameWhat it does
STRING_TO_TABLEOne row for each piece of a string split on a delimiter.
REGEXP_SPLIT_TO_TABLEOne row for each piece of a string split on a regular expression.

Number​

NameWhat it does
ABSThe absolute value of a number.
ROUNDA number rounded to a number of decimal places.
TRUNCA number cut to a number of decimal places, toward zero.
CEILThe smallest whole number not less than a number.
FLOORThe largest whole number not greater than a number.
SIGN-1, 0 or 1 by the sign of a number.
MODThe remainder of one number divided by another.
POWERA number raised to a power.
SQRTThe square root of a number.

Date and time​

NameWhat it does
CURRENT_DATEToday's date in UTC.
EXTRACTOne field of a date or timestamp; with epoch, the way to do date arithmetic.
DATE_PARTOne field of a date or timestamp, such as the year, month or epoch seconds.
DATE_TRUNCA date or timestamp cut back to the start of its year, month, week or other unit.

Conditional​

NameWhat it does
COALESCEThe first argument that is not NULL.
NULLIFNULL when two values are equal, otherwise the first value.
GREATESTThe largest of its arguments, ignoring NULLs.
LEASTThe smallest of its arguments, ignoring NULLs.

Aggregate​

NameWhat it does
COUNTThe number of rows, non-NULL values or distinct values in a group.
SUMThe total of the non-NULL values in a group.
AVGThe mean of the non-NULL values in a group.
MINThe smallest non-NULL value in a group.
MAXThe largest non-NULL value in a group.
STRING_AGGThe values of a group joined into one string with a separator.
ARRAY_AGGThe values of a group collected into a list.

Window​

Ranking​

NameWhat it does
ROW_NUMBERThe position of each row in its partition, counting from 1.
RANKThe rank of each row in its partition, with gaps after ties.
DENSE_RANKThe rank of each row in its partition, with no gaps after ties.
NTILESplits each partition into a number of buckets of near-equal size.
PERCENT_RANKThe relative rank of each row in its partition, from 0 to 1.
CUME_DISTThe share of rows in the partition that sort at or before each row.

Other rows​

NameWhat it does
LAGA value from a row before the current one in the partition.
LEADA value from a row after the current one in the partition.
FIRST_VALUEThe value from the first row of the window frame.
LAST_VALUEThe value from the last row of the window frame.
NTH_VALUEThe value from the nth row of the window frame.