Skip to main content

Scalar Functions

ABS(expr)

Calculates the absolute value of expr

ACOS(expr)

Returns the inverse cosine (arccosine) of expr as a double

ACOSF(expr)

Returns the inverse cosine (arccosine) of expr as a float

ACOSH(expr)

Returns the inverse hyperbolic cosine of expr as a double

ACOSHF(expr)

Returns the inverse hyperbolic cosine of expr as a float

ASIN(expr)

Returns the inverse sine (arcsine) of expr as a double

ASINF(expr)

Returns the inverse sine (arcsine) of expr as a float

ASINH(expr)

Returns the inverse hyperbolic sine of expr as a double

ASINHF(expr)

Returns the inverse hyperbolic sine of expr as a float

ATAN(expr)

Returns the inverse tangent (arctangent) of expr as a double

ATANF(expr)

Returns the inverse tangent (arctangent) of expr as a float

ATANH(expr)

Returns the inverse hyperbolic tangent of expr as a double

ATANHF(expr)

Returns the inverse hyperbolic tangent of expr as a float

ATAN2(x, y)

Returns the inverse tangent (arctangent) using two arguments as a double

ATAN2F(x, y)

Returns the inverse tangent (arctangent) using two arguments as a float

ATN2(x, y)

Alias for ATAN2

ATN2F(x, y)

Alias for ATAN2F

CBRT(expr)

Returns the cube root of expr as a double

CBRTF(expr)

Returns the cube root of expr as a float

CEIL(expr)

Alias for CEILING

CEILING(expr)

Rounds expr up to the next highest integer

COS(expr)

Returns the cosine of expr as a double

COSF(expr)

Returns the cosine of expr as a float

COSH(expr)

Returns the hyperbolic cosine of expr as a double

COSHF(expr)

Returns the hyperbolic cosine of expr as a float

COT(expr)

Returns the cotangent of expr as a double

COTF(expr)

Returns the cotangent of expr as a float

DEGREES(expr)

Returns the conversion of expr (in radians) to degrees as a double

DEGREESF(expr)

Returns the conversion of expr (in radians) to degrees as a float

DIVZ(a, b, c)

Returns the quotient a / b unless b == 0, in which case it returns c

EXP(expr)

Returns e to the power of expr as a double

EXPF(expr)

Returns e to the power of expr as a float

FLOOR(expr)

Rounds expr down to the next lowest integer

GREATER(expr_a, expr_b)

Returns whichever of expr_a and expr_b has the larger value, based on typed comparison

HYPOT(x, y)

Returns the hypotenuse of x and y as a double

HYPOTF(x, y)

Returns the hypotenuse of x and y as a float

IFERROR(expr, val)

Alias for IF_ERROR(expr, val)

IFINF(expr, val)

Alias for IF_INF(expr, val)

IFINFINITY(expr, val)

Alias for IF_INF(expr, val)

IFNAN(expr, val)

Alias for IF_NAN(expr, val)

IF_ERROR(expr, val)

Evaluates the given double or float expr, and if it resolves to infinity or NaN, return val
Conceptually, this function is the same as IF_INF(IF_NAN(expr, val), val)
Example:
Function CallResult
IF_ERROR((double(10)/0), 1)1.0
IF_ERROR(log(-1), 1)1.0

IF_INF(expr, val)

Evaluates the given double or float expr, and if it resolves to infinity, return valExample:
Function CallResult
IF_INF((double(10)/0), 999)999.0
IF_INF(log(-1), 999)NaN

IF_INFINITY(expr, val)

Alias for IF_INF(expr, val)

IF_NAN(expr, val)

Evaluates the given double or float expr, and if it resolves to NaN, return valExample:
Function CallResult
IF_NAN((double(10)/0), -1)Infinity
IF_NAN(log(-1), -1)-1.0

ISINFINITY(expr)

Returns 1 (true) if expr is infinity by IEEE standard; otherwise, returns 0 (false)

IS_INFINITY(expr)

Alias for ISINFINITY

ISNAN(expr)

Returns 1 (true) if expr is not a number by IEEE standard; otherwise, returns 0 (false)

IS_NAN(expr)

Alias for ISNAN

ISNUMERIC(expr)

Returns 1 (true) if expr is a number by IEEE standard; otherwise, returns 0 (false)

IS_NUMERIC(expr)

Alias for ISNUMERIC

LDEXP(x, exp)

Returns the value of x * 2exp as a double

LDEXPF(x, exp)

Returns the value of x * 2exp as a float

LESSER(expr_a, expr_b)

Returns whichever of expr_a and expr_b has the smaller value, based on typed comparison

LN(expr)

Returns the natural logarithm of expr as a double

LNF(expr)

Returns the natural logarithm of expr as a float

LOG(expr)

Alias for LN

LOG10(expr)

Returns the base-10 logarithm of expr as a double

LOG10F(expr)

Returns the base-10 logarithm of expr as a float

LOG1P(expr)

Returns the natural logarithm of one plus expr as a double

LOG1PF(expr)

Returns the natural logarithm of one plus expr as a float

LOG2(expr)

Returns the binary (base-2) logarithm of expr as a double

LOG2F(expr)

Returns the binary (base-2) logarithm of expr as a float

LOGF(expr)

Alias for LNF

MAX_CONSECUTIVE_BITS(expr)

Calculates the length of the longest series of consecutive 1 bits in the integer expr

MOD(dividend, divisor)

Calculates the remainder after integer division of dividend by divisor

NEXT_AFTER(expr[, target])

Returns the next representable floating-point value adjacent to expr in the direction of target, incrementing expr if target is greater, decrementing if lesser. The default value of target is MAX_DOUBLE (always increments when omitted). The return type matches the input (float or double).

NEXT_BEFORE(expr)

Returns the next representable floating-point value less than expr. The return type matches the input (float or double).

PI()

Returns the value of pi

POW(base, exponent)

Alias for POWER

POWF(base, exponent)

Alias for POWERF

POWER(base, exponent)

Returns base raised to the power of exponent as a double

POWERF(base, exponent)

Returns base raised to the power of exponent as a float

RADIANS(expr)

Returns the conversion of expr (in degrees) to radians as a double

RADIANSF(expr)

Returns the conversion of expr (in degrees) to radians as a float

RAND([seed])

Returns a random floating-point value, with an optional seed

REGR_VALX(y, x)

Returns NULL if y is NULL; otherwise, returns x

REGR_VALY(y, x)

Returns NULL if x is NULL; otherwise, returns y

ROUND(expr[, scale])

Rounds expr to the nearest decimal number with scale decimal places when scale is a positive number; rounds to the nearest number such that the result has -(scale) zeros to the left of the decimal point when scale is negative; use scale of 0 to round to the nearest integer.The default value of scale is 0.Examples:
Function CallResult
ROUND(12345.678)12346
ROUND(12345.678, 2)12345.68
ROUND(12345.678, 0)12346
ROUND(12345.678, -2)12300

SAFE_DIVIDE(a, b)

Returns the quotient a / b unless b == 0, in which case it returns NULL

SIGN(expr)

Determines whether a number is positive, negative, or zero; returns one of the following three values:
Expression ValueResult
positive1
zero0
negative-1

SIN(expr)

Returns the sine of expr as a double

SINF(expr)

Returns the sine of expr as a float

SINH(expr)

Returns the hyperbolic sine of expr as a double

SINHF(expr)

Returns the hyperbolic sine of expr as a float

SQRT(expr)

Returns the square root of expr as a double

SQRTF(expr)

Returns the square root of expr as a float

TAN(expr)

Returns the tangent of expr as a double

TANF(expr)

Returns the tangent of expr as a float

TANH(expr)

Returns the hyperbolic tangent of expr as a double

TANHF(expr)

Returns the hyperbolic tangent of expr as a float

TRUNCATE(expr[, scale])

Rounds expr down to the nearest decimal number with scale decimal places when scale is a positive number; rounds down to the nearest number such that the result has -(scale) zeros to the left of the decimal point when scale is negative; use scale of 0 to round down to the nearest integer.The default value of scale is 0.Examples:
Function CallResult
TRUNCATE(12345.678)12345
TRUNCATE(12345.678, 2)12345.67
TRUNCATE(12345.678, 0)12345
TRUNCATE(12345.678, -2)12300

WIDTH_BUCKET(expr, min, max, count)

Defines a set of count equal intervals (buckets) within the range of min & max, and puts the value of expr into one of those buckets, where the value is greater than or equal to the minimum value of the bucket and less than the maximum value of the bucket. Returns the 1-based number of the bucket into which the value of expr fell. For values smaller than min, 0 is returned; for values greater than or equal to max, count + 1 is returned. Examples:In the following examples, a set of 5 equal buckets are defined between 0 and 10 (0-2, 2-4, 4-6, 6-8, & 8-10), and various values are bucketed using that set.
Function CallResult
WIDTH_BUCKET(-1, 0, 10, 5)0
WIDTH_BUCKET(0, 0, 10, 5)1
WIDTH_BUCKET(5, 0, 10, 5)3
WIDTH_BUCKET(10, 0, 10, 5)6
WIDTH_BUCKET(11, 0, 10, 5)6

Aggregate Functions

APPROX_COUNT_DISTINCT(expr)

The approximate number of distinct values of expr; this is faster to calculate than COUNT_DISTINCT but is only an approximation

APPROX_MEDIAN(expr)

The approximate median of expr; the result should be within about 2% of the true median value. This is equivalent to issuing APPROX_PERCENTILE(expr, 50).

APPROX_PERCENTILE(expr, p)

The approximate pth percentile of expr; p should be a value between 0.0 and 100.0. APPROX_PERCENTILE(expr, 50) will return the approximate median of expr.

AVG(expr)

Average of the values of expr

CORR(expr1, expr2)

Correlation coefficient of the values of expr1 and expr2

CORRELATION(expr1, expr2)

Alias for CORR

CORRCOEF(expr1, expr2)

Alias for CORR

COUNT(expr)

Count of non-null values of expr; use * to count all values within an aggregation group or over an entire table

COUNT_DISTINCT(expr)

Count of the distinct values of expr

COV(expr1, expr2)

Alias for COVAR_POP

COVAR(expr1, expr2)

Alias for COVAR_POP

COVARIANCE(expr1, expr2)

Alias for COVAR_POP

COVAR_POP(expr1, expr2)

Population covariance of the values of expr1 and expr2

COVAR_SAMP(expr1, expr2)

Sample covariance of the values of expr1 and expr2

KURT(expr)

Alias for KURTOSIS_POP

KURTOSIS(expr)

Alias for KURTOSIS_POP

KURTOSIS_POP(expr)

Population kurtosis of the values of expr

KURTOSIS_SAMP(expr)

Sample kurtosis of the values of expr

KURT_POP(expr)

Alias for KURTOSIS_POP

KURT_SAMP(expr)

Alias for KURTOSIS_SAMP

MAX(expr)

Maximum of the values of expr

MEAN(expr)

Alias for AVG

MIN(expr)

Minimum of the values of expr

PRODUCT(expr)

Product of the values of expr

REGR_AVGX(y, x)

Average of the independent variable (SUM(x)/N) of the line determined by computing a least-squares-fit linear regression over the given (X, Y) pairs

REGR_AVGY(y, x)

Average of the dependent variable (SUM(y)/N) of the line determined by computing a least-squares-fit linear regression over the given (X, Y) pairs

REGR_COUNT(y, x)

Number of input rows used in computing a linear regression, where both expressions are non-null

REGR_INTERCEPT(y, x)

Y-intercept of the line determined by computing a least-squares-fit linear regression over the given (X, Y) pairs

REGR_R2(y, x)

Square of the correlation coefficient, marking how well the least-squares-fit linear regression fit the data set

REGR_SLOPE(y, x)

Slope of the line determined by computing a least-squares-fit linear regression over the given (X, Y) pairs

REGR_SXX(y, x)

“Sum of squares” of the independent variable (SUM(x^2) - SUM(x)^2/N) of the line determined by computing a least-squares-fit linear regression over the given (X, Y) pairs

REGR_SXY(y, x)

“Sum of Products” of independent variable times dependent variable (SUM(x * y) - SUM(x) * SUM(y)/N) of the line determined by computing a least-squares-fit linear regression over the given (X, Y) pairs

REGR_SYY(y, x)

“Sum of squares” of the dependent variable (SUM(y^2) - SUM(y)^2/N) of the line determined by computing a least-squares-fit linear regression over the given (X, Y) pairs

SKEW(expr)

Alias for SKEWNESS_POP

SKEWNESS(expr)

Alias for SKEWNESS_POP

SKEWNESS_POP(expr)

Population skew of the values of expr

SKEWNESS_SAMP(expr)

Sample skew of the values of expr

SKEW_POP(expr)

Alias for SKEWNESS_POP

SKEW_SAMP(expr)

Alias for SKEWNESS_SAMP

STDDEV(expr)

Population standard deviation over values of expr (i.e. the denominator is N)

STDDEV_POP(expr)

Population standard deviation over values of expr (i.e. the denominator is N)

STDDEV_SAMP(expr)

Sample standard deviation over values of expr (i.e. the denominator is N-1)

SUM(expr)

Sum of the values of expr

VAR(expr)

Population variance over values of expr (i.e. the denominator is N)

VAR_POP(expr)

Population variance over values of expr (i.e. the denominator is N)

VAR_SAMP(expr)

Sample variance over values of expr (i.e. the denominator is N-1)

VARIANCE(expr)

Alias for VAR

VARIANCE_POP(expr)

Alias for VAR_POP

VARIANCE_SAMP(expr)

Alias for VAR_SAMP