Available for:
Questions / Feedback?

# Projection Functions

CData Power BI Connector for MarkLogic 2019 - Build 19.0.7354

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

## DATE_PART_YEAR(date)

The DATE_PART_YEAR function extracts the year from a date.

• date: A date column or an expression that implicitly converts to a date.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATE_PART(datepart, expression)

DATE_PART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## GETDATE()

GETDATE returns the current date and time in the current session time zone (UTC by default).

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## SYSDATE

SYSDATE returns the current date and time in the current session time zone (UTC by default).

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## DLOG1(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## LOG(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## DLOG10(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CHR(number)

The CHR function returns the character that matches the ASCII code point value specified by of the input parameter.

• number: The input parameter is an integer that represents an ASCII code point value.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLICATE(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPLICATE treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## DLOG1(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## LOG(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## DLOG10(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## DLOG1(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## LOG(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## DLOG10(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## DLOG1(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## LOG(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## DLOG10(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## DLOG1(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## LOG(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## DLOG10(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## DLOG1(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## LOG(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## DLOG10(expression)

Returns the base 10 logarithm of a number.

• expression: A double precision number.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.
• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_SCHEMA_PRIVILEGE(schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_SCHEMA_PRIVILEGE(user, schema, privilege)

Returns true if the user has the specified privilege for the specified schema.

• user: Name of the user to check for schema privileges. Default is to check the current user.
• schema: Schema associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, USAGE.

## HAS_TABLE_PRIVILEGE(table, privilege)

Returns true if the user has the specified privilege for the specified table.

• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## HAS_TABLE_PRIVILEGE(user, table, privilege)

Returns true if the user has the specified privilege for the specified table.

• user: Name of the user to check for table privileges. Default is to check the current user.
• table: Table associated with the privilege.
• privilege: Privilege to check. Valid values: SELECT, INSERT, UPDATE, DELETE, REFERENCES.

## CURRENT_SCHEMAS(include_implicit)

Returns an array of the names of any schemas in the current search path. The current search path is defined in the search_path parameter.

• include_implicit: If true, specifies that the search path should include any implicitly included system schemas. Valid values are true and false. Typically, if true, this parameter returns the pg_catalog schema in addition to the current schema.

## PG_GET_COLS(name)

Returns the column metadata for a table or view definition.

• name: The name of an Amazon Redshift table or view.

## AVG([(DISTINCT/ALL)] expression)

The AVG function returns the average (arithmetic mean) of the input expression values. The AVG function works with numeric values and ignores NULL values.

• expression: The expression to use to compute the average.

## COUNT([(DISTINCT/ALL)] expression)

The COUNT function counts the rows defined by the expression.

• expression: The expression to use to compute the count.

## MAX([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the max.

## MIN([(DISTINCT/ALL)] expression)

The MIN function returns the minimum value in a set of rows. DISTINCT or ALL may be used but do not affect the result.

• expression: The expression to use to compute the min.

## SUM([(DISTINCT/ALL)] expression)

Returns the sum on non-null values. Each distinct value of expression is aggregated only once into the result.

• expression: The expression to use to compute the sum.

## LISTAGG([DISTINCT] expression [, delimiter])

For each group in a query, the LISTAGG aggregate function orders the rows for that group according to the ORDER BY expression, then concatenates the values into a single string.

• aggregate_expression: Any valid expression.
• delimiter: The string constant to separate the concatenated values. The default is NULL.

## MEDIAN(expression)

Calculates the median value for the range of values. NULL values in the range are ignored.

• expression: Any valid expression.

## STDDEV([(DISTINCT/ALL)] expression)

The STDDEV function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_SAMP([(DISTINCT/ALL)] expression)

The STDDEV_SAMP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## STDDEV_POP([(DISTINCT/ALL)] expression)

The STDDEV_POP function returns the sample and population standard deviation of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_SAMP([(DISTINCT/ALL)] expression)

The VAR_SAMP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VARIANCE([(DISTINCT/ALL)] expression)

The VARIANCE function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## VAR_POP([(DISTINCT/ALL)] expression)

The VAR_POP function returns the sample and population variance of a set of numeric values (integer, decimal, or floating-point).

• expression: Any valid expression.

## BIT_OR([(DISTINCT/ALL)] expression)

The BIT_OR function runs a bit-wise OR operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BIT_AND([(DISTINCT/ALL)] expression)

The BIT_AND function runs a bit-wise AND operation on all of the values in a single integer column or expression.

• expression: The target column or expression that the function operates on. This expression must have an INT, INT2, or INT8 data type.

## BOOL_OR([(DISTINCT/ALL)] expression)

The BOOL_OR function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## BOOL_AND([(DISTINCT/ALL)] expression)

The BOOL_AND function operates on a single Boolean or integer column or expression. This function applies similar logic to the BIT_AND and BIT_OR functions. For these functions, the return type is a Boolean value (true or false).

• expression: The target column or expression that the function operates on. This expression must have a BOOLEAN or integer data type.

## CUME_DIST()

Calculates the cumulative distribution of a value within a window or partition.

## DENSE_RANK()

The DENSE_RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## FIRST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the first row in the current window frame.

• value_expression: Any value expression

## LAST_VALUE(value_expression [(IGNORE/RESPECT) NULLS])

Returns the value of the value_expression for the last row in the current window frame.

• value_expression: Any value expression

## LAG(expression [, offset])

The LAG window function returns the values for a row at a given offset above (before) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

The LEAD window function returns the values for a row at a given offset below (after) the current row in the partition.

• expression: The target column or expression that the function operates on.
• offset: An optional parameter that specifies the number of rows before the current row to return values for. If you do not specify an offset, Amazon Redshift uses 1 as the default value. An offset of 0 indicates the current row.

## NTH_VALUE(expression, offset)

The NTH_VALUE window function returns the expression value of the specified row of the window frame relative to the first row of the window.

• expression: The target column or expression that the function operates on.
• offset: Determines the row number relative to the first row in the window for which to return the expression. The offset can be a constant or an expression and must be a positive integer that is greater than 0.

## NTILE(expression)

The NTILE window function divides ordered rows in the partition into the specified number of ranked groups of as equal size as possible and returns the group that a given row falls into.

• expression: The number of ranking groups and must result in a positive integer value (greater than 0) for each partition. The expression argument must not be nullable.

## PERCENT_RANK()

Calculates the percent rank of a given row.

## PERCENTILE_CONT(percentile)

PERCENTILE_CONT is an inverse distribution function that assumes a continuous distribution model. It takes a percentile value and a sort specification, and returns an interpolated value that would fall into the given percentile value with respect to the sort specification.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## PERCENTILE_DISC(percentile)

PERCENTILE_DISC is an inverse distribution function that assumes a discrete distribution model. It takes a percentile value and a sort specification and returns an element from the given set.

• percentile: Numeric constant between 0 and 1. Nulls are ignored in the calculation.

## RANK()

The RANK window function determines the rank of a value in a group of values, based on the ORDER BY expression in the OVER clause.

## RATIO_TO_REPORT(expression)

Calculates the ratio of a value to the sum of the values in a window or partition.

• expression: An expression, such as a column name, that provides the value for which to determine the ratio. The expression must have either a numeric data type or be implicitly convertible to one.

## ROW_NUMBER()

Determines the ordinal number of the current row within a group of rows, counting from 1, based on the ORDER BY expression in the OVER clause.

## COALESCE(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL(expr1 [, expr2 [, ...]])

An NVL or COALESCE expression returns the value of the first expression in the list that is not null. If all expressions are null, the result is null. When a non-null value is found, the remaining expressions in the list are not evaluated.

• expr1: Any valid expression.
• expr2: Any valid expression.

## DECODE(expression, search, result [[, search2, result2], default])

A DECODE expression replaces a specific value with either another specific value or a default value, depending on the result of an equality condition. This operation is equivalent to the operation of a simple CASE expression or an IF-THEN-ELSE statement.

• expression: The source of the value that you want to compare, such as a column in a table.
• search: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result: The replacement value that query returns when the expression matches the search value.
• search2: The target value that is compared against the source expression, such as a numeric value or a character string. The search expression must evaluate to a single fixed value.
• result2: The replacement value that query returns when the expression matches the search value.
• default: An optional default value that is used for cases when the search condition fails. If you do not specify a default value, the DECODE expression returns NULL.

## GREATEST(expr1 [, expr2 [, ...]])

Returns the largest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## LEAST(expr1 [, expr2 [, ...]])

Returns the smallest value from a list of any number of expressions.

• expr1: Any valid expression.
• expr2: Any valid expression.

## NVL2(expression, not_null_return_value, null_return_value)

Returns one of two values based on whether a specified expression evaluates to NULL or NOT NULL.

• expression: An expression, such as a column name, to be evaluated for null status.
• not_null_return_value: The value returned if expression evaluates to NOT NULL. The not_null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.
• null_return_value: The value returned if expression evaluates to NULL. The null_return_value value must either have the same data type as expression or be implicitly convertible to that data type.

## NULLIF(expression1, expression2)

The NULLIF expression compares two arguments and returns null if the arguments are equal. If they are not equal, the first argument is returned. This expression is the inverse of the NVL or COALESCE expression.

• expression1: The target columns or expressions that are compared.
• expression2: The target columns or expressions that are compared.

ADD_MONTHS adds the specified number of months to a date or time stamp value or expression.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• num_months: A positive or negative integer. Use a negative number to subtract months from dates.

## CURRENT_DATE()

CURRENT_DATE returns a date in the current session time zone (UTC by default) in the default format: YYYY-MM-DD..

## CONVERT_TIMEZONE(target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## CONVERT_TIMEZONE(source_timezone, target_timezone, expression)

CONVERT_TIMEZONE converts a time stamp from one time zone to another.

• source_timezone: (Optional) The time zone of the current time stamp. The default is UTC.
• target_timezone: The time zone for the new time stamp.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP(date1, date2)

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

• date1: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• date2: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## DATE_CMP_TIMESTAMP(date, timestamp)

Compares a date to a time stamp and returns 0 if the values are identical, 1 if date is greater alphabetically and -1 if timestamp is greater.

• date: A date column or an expression that implicitly converts to a date.
• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.

## DATE_CMP_TIMESTAMPTZ(date, timestamptz)

DATE_CMP_TIMESTAMPTZ compares a date to a time stamp with time zone. If the date and time stamp values are identical, the function returns 0. If the date is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• date: A DATE column or an expression that implicitly converts to a date.
• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.

Increments a date or time stamp value by a specified interval.

• datepart: The date part (year, month, or day, for example) that the function operates on.
• interval: An integer that specified the interval (number of days, for example) to add to the target expression. A negative integer subtracts the interval.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The date or time stamp expression must contain the specified date part.

## DATEDIFF(datepart, expression1, expression2)

DATEDIFF returns the difference between the date parts of two date or time expressions. If the second date or time is later than the first date or time, the result is positive. If the second date or time is earlier than the first date or time, the result is negative.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression1: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.
• expression2: A date or timestamp columns or expressions that implicitly convert to a date or time stamp. The expressions must both contain the specified date part.

## DATEPART(datepart, expression)

DATEPART extracts datepart values from an expression.

• datepart: The specific part of the date value (year, month, or day, for example) that the function operates on.
• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp. The expression must be a date or time stamp expression that contains the specified datepart.

## DATE_TRUNC(datepart, expression)

The DATE_TRUNC function truncates a time stamp expression or literal based on the date part that you specify, such as hour, week, or month. DATE_TRUNC returns the first day of the specified year, the first day of the specified month, or the Monday of the specified week.

• datepart: The date part to which to truncate the time stamp value.
• expression: A timestamp column or an expression that implicitly converts to a time stamp.

## DAY(date)

DAY returns the day of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## EXTRACT(datepart FROM expression)

The EXTRACT function returns a date part, such as a day, month, or year, from a time stamp value or expression.

• datepart: The date part to extract.
• expression: A TIMESTAMP or TIMESTAMPTZ column, or an expression that implicitly converts to a time stamp or time stamp with time zone.

## INTERVAL_CMP(interval1, interval2)

INTERVAL_CMP compares two intervals and returns 1 if the first interval is greater, -1 if the second interval is greater, and 0 if the intervals are equal.

• interval1: An interval literal value.
• interval2: An interval literal value.

## LAST_DAY(expression)

LAST_DAY returns the date of the last day of the month that contains date.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## MONTHS_BETWEEN(date1, date2)

MONTHS_BETWEEN determines the number of months between two dates. If the first date is later than the second date, the result is positive; otherwise, the result is negative. If either argument is null, the result is NULL.

• date1: An expression, such as a column name, that evaluates to a valid date or time stamp value.
• date2: An expression, such as a column name, that evaluates to a valid date or time stamp value.

## NEXT_DAY(expression, day)

NEXT_DAY returns the date of the first instance of the specified day that is later than the given date. If the day value is the same day of the week as given_date, the next occurrence of that day is returned.

• expression: A date or timestamp column or an expression that implicitly converts to a date or time stamp.
• day: A string containing the name of any day. Capitalization does not matter.

## TIMEOFDAY()

TIMEOFDAY is a special alias used to return the weekday, date, and time as a string value.

## TIMESTAMP_CMP(timestamp1, timestamp2)

Compares the value of two time stamps and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamp1: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamp2: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMESTAMP_CMP_DATE(timestamp, date)

TIMESTAMP_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamp: A timestamp column or an expression that implicitly converts to a time stamp.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMP_CMP_TIMESTAMPTZ(timestamp, timestamptz)

TIMESTAMP_CMP_TIMESTAMPTZ compares the value of a time stamp expression with a time stamp with time zone expression. If the time stamp and time stamp with time zone values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the time stamp with time zone is greater, the function returns -1.

• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.
• timestamptz: A TIMESTAMP column or an expression that implicitly converts to a time stamp with a time zone.

## TIMESTAMPTZ_CMP(timestamptz1, timestamptz2)

TIMESTAMPTZ_CMP compares the value of two time stamp with time zone values and returns an integer. If the time stamps are identical, the function returns 0. If the first time stamp is greater alphabetically, the function returns 1. If the second time stamp is greater, the function returns -1.

• timestamptz1: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.
• timestamptz2: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with time zone.

## TIMESTAMPTZ_CMP_DATE(timestamptz, date)

TIMESTAMPTZ_CMP_DATE compares the value of a time stamp and a date. If the time stamp and date values are identical, the function returns 0. If the time stamp is greater alphabetically, the function returns 1. If the date is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• date: A date column or an expression that implicitly converts to a date.

## TIMESTAMPTZ_CMP_TIMESTAMP(timestamptz, timestamp)

TIMESTAMPTZ_CMP_TIMESTAMP compares the value of a time stamp with time zone expression with a time stamp expression. If the time stamp with time zone and time stamp values are identical, the function returns 0. If the time stamp with time zone is greater alphabetically, the function returns 1. If the time stamp is greater, the function returns -1.

• timestamptz: A TIMESTAMPTZ column or an expression that implicitly converts to a time stamp with a time zone.
• timestamp: A TIMESTAMP column or an expression that implicitly converts to a time stamp.

## TIMEZONE(timezone, expression)

TIMEZONE returns a time stamp for the specified time zone and time stamp value.

• timezone: The time zone for the return value. The time zone can be specified as a time zone name (such as 'Africa/Kampala' or 'Singapore') or as a time zone abbreviation (such as 'UTC' or 'PDT').
• expression: An expression that results in a TIMESTAMP or TIMESTAMPTZ type, or a value that can implicitly be coerced to a time stamp.

## TO_TIMESTAMP(timestampstr, format)

TO_TIMESTAMP converts a TIMESTAMP string to TIMESTAMPTZ.

• timestampstr: A string that represents a time stamp value in the format specified by format.
• format: The format for the timestamp value.

## YEAR(date)

YEAR returns the year of the specified date.

• date: A date or timestamp column or an expression that implicitly converts to a date or time stamp.

## TRUNC(expression [, decimalplaces])

Truncates a time stamp and returns a date.

• expression: Can be a numeric data type or a timestamp column or an expression that implicitly converts to a time stamp.
• decimalplaces: An integer that indicates the number of decimal places of precision, in either direction.

## ABS(expression)

ABS calculates the absolute value of a number, where that number can be a literal or an expression that evaluates to a number.

• expression: Number or expression that evaluates to a number.

## ACOS(expression)

ACOS is a trigonometric function that returns the arc cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ASIN(expression)

ASIN is a trigonometric function that returns the arc sine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN(expression)

ATAN is a trigonometric function that returns the arc tangent of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## ATAN2(expression1, expression2)

ATAN2 is a trigonometric function that returns the arc tangent of a one number divided by another number. The return value is in radians and is between PI/2 and -PI/2.

• expression1: A double precision number.
• expression2: A double precision number.

## CBRT(expression)

The CBRT function is a mathematical function that calculates the cube root of a number.

• expression: A double precision number.

## CEIL(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CEILING(expression)

The CEILING or CEIL function is used to round a number up to the next whole number.

• expression: A double precision number.

## CHECKSUM(expression)

Computes a checksum value for building a hash index.

• expression: The input expression must be a VARCHAR, INTEGER, or DECIMAL data type.

## COS(expression)

COS is a trigonometric function that returns the cosine of a number. The return value is in radians and is between PI/2 and -PI/2.

• expression: A double precision number.

## COT(expression)

COT is a trigonometric function that returns the cotangent of a number. The input parameter must be nonzero.

• expression: A double precision number.

## DEGREES(expression)

Converts an angle in radians to its equivalent in degrees.

• expression: A double precision number.

## DEXP(expression)

The DEXP function returns the exponential value in scientific notation for a double precision number. The only difference between the DEXP and EXP functions is that the parameter for DEXP must be a double precision.

• expression: A double precision number.

## EXP(expression)

The EXP function returns the exponential value in scientific notation for a numeric expression.

• expression: The expression must be an INTEGER, DECIMAL, or DOUBLE PRECISION data type.

## FLOOR(expression)

The FLOOR function rounds a number down to the next whole number.

• expression: A double precision number.

## LN(expression)

Returns the natural logarithm of the input parameter.

• expression: The target column or expression that the function operates on.

## MOD(number1, number2)

The MOD function returns a numeric result that is the remainder of two numeric parameters. The first parameter is divided by the second parameter.

• number1: The first input parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number.
• number2: The second parameter is an INTEGER, SMALLINT, BIGINT, or DECIMAL number. The same data type rules apply to number2 as to number1.

## PI()

The PI function returns the value of PI to 14 decimal places.

## POW(expression1, expression2)

The POW function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

## POWER(expression1, expression2)

The POWER function is an exponential function that raises a numeric expression to the power of a second numeric expression.

• expression1: Numeric expression to be raised. Must be an integer, decimal, or floating-point data type.
• expression2: Power to raise expression1. Must be an integer, decimal, or floating-point data type.

Converts an angle in degrees to its equivalent in radians.

• expression: A double precision number.

## RANDOM()

The RANDOM function generates a random value between 0.0 and 1.0.

## ROUND(expression [, decimalplaces])

The ROUND function rounds numbers to the nearest integer or decimal.

• expression: INTEGER, DECIMAL, and FLOAT data types are supported.
• decimalplaces: An integer to indicate the number of decimal places for rounding.

## SIN(expression)

SIN is a trigonometric function that returns the sine of a number. The return value is between -1 and 1.

• expression: A double precision number.

## SIGN(expression)

The SIGN function returns the sign (positive or negative) of a number. The result of the SIGN function is 1, -1, or 0 indicating the sign of the argument.

• expression: Number to be evaluated. The data type can be numeric or double precision.

## SQRT(expression)

The SQRT function returns the square root of a numeric value.

• expression: The expression must have an integer, decimal, or floating-point data type.

## TAN(expression)

TAN is a trigonometric function that returns the tangent of a number. The input parameter must be a non-zero number (in radians).

• expression: A double precision number.

## TO_HEX(expression)

The TO_HEX function converts a number to its equivalent hexadecimal value.

• expression: A number to convert to its hexadecimal value.

## BPCHARCMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTTEXT_PATTERN_CMP(str1, str2)

Compares the value of two string and returns an integer. If the string are identical, returns 0. If the first string is "greater" alphabetically, returns 1. If the second string is "greater", returns -1.

• str1: A CHAR or VARCHAR string.
• str2: A CHAR or VARCHAR string.

## BTRIM(expression, matching_string )

The BTRIM function trims a string by removing leading and trailing blanks or by removing characters that match an optional specified string.

• expression: A string expression.
• matching_string: The string to match and trim.

## LEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHAR_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARACTER_LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## LENGTH(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## TEXTLEN(expression)

Returns the length of the specified string as the number of characters.

• expression: A string expression.

## CHARINDEX(substring, expression)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the expression.
• expression: A string expression.

## CONCAT(str1, str2)

The CONCAT function concatenates two character string and returns the resulting string.

• str1: A string expression.
• str2: A string expression.

## CRC32(expression)

CRC32 is an error-detecting function that uses a CRC32 algorithm to detect changes between source and target data. The CRC32 function converts a variable-length string into an 8-character string that is a text representation of the hexadecimal value of a 32 bit-binary sequence.

• expression: A string expression.

## FUNC_SHA1(expression)

The FUNC_SHA1 function uses the SHA1 cryptographic hash function to convert a variable-length string into a 40-character string that is a text representation of the hexadecimal value of a 160-bit checksum.

• expression: A string expression.

## INITCAP(expression)

Capitalizes the first letter of each word in a specified string. INITCAP supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## LEFT(expression, num)

Returns the specified number of leftmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## RIGHT(expression, num)

Returns the specified number of rightmost characters from a character string.

• expression: A string expression.
• num: A positive integer.

## LOWER(expression)

Converts a string to lowercase. LOWER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

Appends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are appended to string1. This argument is optional; if it is not specified, spaces are used.

Prepends characters to a string, based on a specified length.

• string1: A character string or an expression that evaluates to a character string, such as the name of a character column.
• length: An integer that defines the length of the result of the function.
• string2: One or more characters that are prepended to string1. This argument is optional; if it is not specified, spaces are used.

## LTRIM(expression, trim_chars)

The LTRIM function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

The TRIMLEADING function trims a specified set of characters from the beginning of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the beginning of string.

## MD5(expression)

Uses the MD5 cryptographic hash function to convert a variable-length string into a 32-character string that is a text representation of the hexadecimal value of a 128-bit checksum.

• expression: A variable-length string.

## OCTET_LENGTH(expression)

Returns the length of the specified string as the number of bytes.

• expression: A string expression.

## POSITION(substring IN string)

Returns the location of the specified substring within a string.

• substring: The substring to search for within the string.
• string: The string or column to be searched.

## QUOTE_IDENT(expression)

The QUOTE_IDENT function returns the specified string as a double quoted string so that it can be used as an identifier in a SQL statement. Appropriately doubles any embedded double quotes.

• expression: A string expression

## QUOTE_LITERAL(expression)

The QUOTE_LITERAL function returns the specified string as a quoted string so that it can be used as a string literal in a SQL statement. If the input parameter is a number, QUOTE_LITERAL treats it as a string. Appropriately doubles any embedded single quotes and backslashes.

• expression: A string expression

## REGEXP_COUNT(source_string, pattern [, position])

Searches a string for a regular expression pattern and returns an integer that indicates the number of times the pattern occurs in the string. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_INSTR(source_string, pattern [, position [, occurrence [, option [, parameters]]]])

Searches a string for a regular expression pattern and returns an integer that indicates the beginning position or ending position of the matched substring. If no match is found, then the function returns 0.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_INSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is 0.
• option: A value that indicates whether to return the position of the first character of the match (0) or the position of the first character following the end of the match (1). A nonzero value is the same as 1. The default value is 0.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REGEXP_REPLACE(source_string, pattern [, replace_string [, position]])

Searches a string for a regular expression pattern and replaces every occurrence of the pattern with the specified string.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• replace_string: A string expression, such as a column name, that will replace each occurrence of pattern. The default is an empty string.
• position: A positive integer that indicates the position within source_string to begin searching.

## REGEXP_SUBSTR(source_string, pattern [, position [, occurrence [, parameters]]])

Returns the characters extracted from a string by searching for a regular expression pattern.

• source_string: A string expression, such as a column name, to be searched.
• pattern: A string literal that represents a SQL standard regular expression pattern.
• position: A positive integer that indicates the position within source_string to begin searching.
• occurrence: A positive integer that indicates which occurrence of the pattern to use. REGEXP_SUBSTR skips the first occurrence -1 matches. The default is 1. If occurrence is less than 1 or greater than the number of characters in source_string, the search is ignored and the result is NULL.
• parameters: One or more string literals that indicate how the function matches the pattern.

## REPEAT(expression, numrepeats)

Repeats a string the specified number of times. If the input parameter is numeric, REPEAT treats it as a string.

• expression: The first input parameter is the string to be repeated.
• numrepeats: An integer indicating the number of times to repeat the string.

## REPLACE(expression, old_chars, new_chars)

Replaces all occurrences of a set of characters within an existing string with other specified characters.

• expression: CHAR or VARCHAR string to be searched search
• old_chars: CHAR or VARCHAR string to replace.
• new_chars: New CHAR or VARCHAR string replacing the old_string.

## REVERSE(expression)

The REVERSE function operates on a string and returns the characters in reverse order.

• expression: An expression with a character, date, time stamp, or numeric data type that represents the target of the character reversal. All expressions are implicitly converted to variable-length character strings. Trailing blanks in fixed-width character strings are ignored.

## RTRIM(expression, trim_chars)

The RTRIM function trims a specified set of characters from the end of a string.

• expression: The string column or expression to be trimmed.
• trim_chars: A string column or expression representing the characters to be trimmed from the end of string.

## SPLIT_PART(expression, delimiter, part)

Splits a string on the specified delimiter and returns the part at the specified position.

• expression: The string to be split.
• delimiter: The delimiter string.
• part: Position of the portion to return (counting from 1). Must be an integer greater than 0. If part is larger than the number of string portions, SPLIT_PART returns an empty string.

## STRPOS(string, substring)

Returns the position of a substring within a specified string.

• string: The string to be searched.
• substring: The substring to search for within the string.

## STRTOL(num_string, base)

Converts a string expression of a number of the specified base to the equivalent integer value. The converted value must be within the signed 64-bit range.

• num_string: String expression of a number to be converted. If num_string is empty ( '' ) or begins with the null character ('\0'), the converted value is 0. If num_string is a column containing a NULL value, STRTOL returns NULL. The string can begin with any amount of white space, optionally followed by a single plus '+' or minus '-' sign to indicate positive or negative. The default is '+'. If base is 16, the string can optionally begin with '0x'.
• base: Integer between 2 and 36.

## SUBSTRING(expression, start_position, number_chars)

Returns the characters extracted from a string based on the specified character position for a specified number of characters.

• expression: The string to be searched. Non-character data types are treated like a string.
• start_position: The position within the string to begin the extraction, starting at 1.
• number_chars: The number of characters to extract (the length of the substring).

## TRANSLATE(expression, characters_to_replace, characters_to_substitute)

For a given expression, replaces all occurrences of specified characters with specified substitutes. Existing characters are mapped to replacement characters by their positions in the characters_to_replace and characters_to_substitute arguments.

• expression: The expression to be translated.
• characters_to_replace: A string containing the characters to be replaced.
• characters_to_substitute: A string containing the characters to substitute.

## UPPER(expression)

Converts a string to uppercase. UPPER supports UTF-8 multibyte characters, up to a maximum of four bytes per character.

• expression: A string expression.

## CAST(expression AS type)

Cast is used in a query to indicate that the result type of an expression should be converted to some other type.

• expression: The expression to cast.
• type: The type to cast the expression to.

## TO_CHAR(expression, format)

TO_CHAR converts a time stamp or numeric expression to a character-string data format.

• expression: A numeric or timestamp expression.
• format: The format for the new value.

## TO_DATE(expression, format)

TO_DATE converts a date represented in a character string to a DATE data type.

• expression: String to be converted.
• format: A string literal that defines the format of the output, in terms of its date parts.

## TO_NUMBER(string, format)

TO_NUMBER converts a string to a numeric (decimal) value.

• string: String to be converted. The format must be a literal value.
• format: A format string that indicates how the character string should be parsed to create the numeric value.

## CURRENT_SETTING(parameter)

CURRENT_SETTING returns the current value of the specified configuration parameter.

• parameter: Parameter value to display.

## PG_CANCEL_BACKEND(pid)

Cancels a query. PG_CANCEL_BACKEND is functionally equivalent to the CANCEL command. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## CANCEL(pid)

Cancels a query. You can cancel queries currently being run by your user. Superusers can cancel any query.

• pid: The process ID (PID) of the query to be canceled. You cannot cancel a query by specifying a query ID; you must specify the query's process ID.

## PG_TERMINATE_BACKEND(pid)

Terminates a session. You can terminate a session owned by your user. A superuser can terminate any session.

• pid: The process ID of the session to be terminated.

## SET_CONFIG(parameter, new_value, is_local)

Sets a configuration parameter to a new setting.

• parameter: Parameter to set.
• new_value: New value of the parameter.
• is_local: If true, parameter value applies only to the current transaction. Valid values are true or 1 and false or 0.

## CURRENT_DATABASE()

Returns the name of the database where you are currently connected.

## CURRENT_SCHEMA()

Returns the name of the schema at the front of the search path. This schema will be used for any tables or other named objects that are created without specifying a target schema.

## CURRENT_USER()

Returns the user name of the current "effective" user of the database, as applicable to checking permissions. Usually, this user name will be the same as the session user; however, this can occasionally be changed by superusers.

## CURRENT_USER_ID()

Returns the unique identifier for the Amazon Redshift user logged in to the current session.

## PG_BACKEND_PID()

Returns the process ID (PID) of the server process handling the current session.

## PG_GET_LATE_BINDING_VIEW_COLS()

Returns the column metadata for all late-binding views in the database.

## PG_LAST_COPY_COUNT()

Returns the number of rows that were loaded by the last COPY command executed in the current session. PG_LAST_COPY_COUNT is updated with the last COPY ID, which is the query ID of the last COPY that began the load process, even if the load failed. The query ID and COPY ID are updated when the COPY command begins the load process.

## PG_LAST_COPY_ID()

Returns the query ID of the most recently executed COPY command in the current session. If no COPY commands have been executed in the current session, PG_LAST_COPY_ID returns -1.

Returns the query ID of the most recently executed UNLOAD command in the current session. If no UNLOAD commands have been executed in the current session, PG_LAST_UNLOAD_ID returns -1.

## PG_LAST_QUERY_ID()

Returns the query ID of the most recently executed query in the current session. If no queries have been executed in the current session, PG_LAST_QUERY_ID returns -1. PG_LAST_QUERY_ID does not return the query ID for queries that execute exclusively on the leader node.

## SESSION_USER()

Returns the name of the user associated with the current session. This is the user who initiated the current database connection.

## SLICE_NUM()

Returns an integer corresponding to the slice number in the cluster where the data for a row is located. SLICE_NUM takes no parameters.

## USER()

Synonym for CURRENT_USER.

## VERSION()

The VERSION() function returns details about the currently installed release, with specific Amazon Redshift version information at the end.

## HAS_DATABASE_PRIVILEGE(database, privilege)

Returns true if the user has the specified privilege for the specified database.

• database: Database associated with the privilege.
• privilege: Privilege to check. Valid values: CREATE, TEMPORARY, TEMP.

## HAS_DATABASE_PRIVILEGE(user, database, privilege)

Returns true if the user has the specified privilege for the specified database.

• user: Name of the user to check for database privileges. Default is to check the current user.