Scalar Functions
ABS(expr)
ABS(expr)
exprACOS(expr)
ACOS(expr)
expr as a doubleACOSF(expr)
ACOSF(expr)
expr as a floatACOSH(expr)
ACOSH(expr)
expr as a doubleACOSHF(expr)
ACOSHF(expr)
expr as a floatASIN(expr)
ASIN(expr)
expr as a doubleASINF(expr)
ASINF(expr)
expr as a floatASINH(expr)
ASINH(expr)
expr as a doubleASINHF(expr)
ASINHF(expr)
expr as a floatATAN(expr)
ATAN(expr)
expr as a doubleATANF(expr)
ATANF(expr)
expr as a floatATANH(expr)
ATANH(expr)
expr as a doubleATANHF(expr)
ATANHF(expr)
expr as a floatATAN2(x, y)
ATAN2(x, y)
ATAN2F(x, y)
ATAN2F(x, y)
ATN2(x, y)
ATN2(x, y)
ATAN2ATN2F(x, y)
ATN2F(x, y)
ATAN2FCBRT(expr)
CBRT(expr)
expr as a doubleCBRTF(expr)
CBRTF(expr)
expr as a floatCEIL(expr)
CEIL(expr)
CEILINGCEILING(expr)
CEILING(expr)
expr up to the next highest integerCOS(expr)
COS(expr)
expr as a doubleCOSF(expr)
COSF(expr)
expr as a floatCOSH(expr)
COSH(expr)
expr as a doubleCOSHF(expr)
COSHF(expr)
expr as a floatCOT(expr)
COT(expr)
expr as a doubleCOTF(expr)
COTF(expr)
expr as a floatDEGREES(expr)
DEGREES(expr)
expr (in radians) to degrees as a doubleDEGREESF(expr)
DEGREESF(expr)
expr (in radians) to degrees as a floatDIVZ(a, b, c)
DIVZ(a, b, c)
a / b unless b == 0, in which case it returns cEXP(expr)
EXP(expr)
expr as a doubleEXPF(expr)
EXPF(expr)
expr as a floatFLOOR(expr)
FLOOR(expr)
expr down to the next lowest integerGREATER(expr_a, expr_b)
GREATER(expr_a, expr_b)
expr_a and expr_b has the larger value, based on typed
comparisonHYPOT(x, y)
HYPOT(x, y)
x and y as a doubleHYPOTF(x, y)
HYPOTF(x, y)
x and y as a floatIFERROR(expr, val)
IFERROR(expr, val)
IF_ERROR(expr, val)IFINF(expr, val)
IFINF(expr, val)
IF_INF(expr, val)IFINFINITY(expr, val)
IFINFINITY(expr, val)
IF_INF(expr, val)IFNAN(expr, val)
IFNAN(expr, val)
IF_NAN(expr, val)IF_ERROR(expr, val)
IF_ERROR(expr, val)
expr, and if it resolves to infinity or
NaN, return valExample:| Function Call | Result |
|---|---|
IF_ERROR((double(10)/0), 1) | 1.0 |
IF_ERROR(log(-1), 1) | 1.0 |
IF_INF(expr, val)
IF_INF(expr, val)
expr, and if it resolves to infinity,
return valExample:| Function Call | Result |
|---|---|
IF_INF((double(10)/0), 999) | 999.0 |
IF_INF(log(-1), 999) | NaN |
IF_INFINITY(expr, val)
IF_INFINITY(expr, val)
IF_INF(expr, val)IF_NAN(expr, val)
IF_NAN(expr, val)
expr, and if it resolves to NaN,
return valExample:| Function Call | Result |
|---|---|
IF_NAN((double(10)/0), -1) | Infinity |
IF_NAN(log(-1), -1) | -1.0 |
ISINFINITY(expr)
ISINFINITY(expr)
1 (true) if expr is infinity by IEEE standard; otherwise, returns
0 (false)IS_INFINITY(expr)
IS_INFINITY(expr)
ISINFINITYISNAN(expr)
ISNAN(expr)
1 (true) if expr is not a number by IEEE standard; otherwise, returns
0 (false)IS_NAN(expr)
IS_NAN(expr)
ISNANISNUMERIC(expr)
ISNUMERIC(expr)
1 (true) if expr is a number by IEEE standard; otherwise, returns
0 (false)IS_NUMERIC(expr)
IS_NUMERIC(expr)
ISNUMERICLDEXP(x, exp)
LDEXP(x, exp)
x * 2exp as a doubleLDEXPF(x, exp)
LDEXPF(x, exp)
x * 2exp as a floatLESSER(expr_a, expr_b)
LESSER(expr_a, expr_b)
expr_a and expr_b has the smaller value, based on typed
comparisonLN(expr)
LN(expr)
expr as a doubleLNF(expr)
LNF(expr)
expr as a floatLOG(expr)
LOG(expr)
LNLOG10(expr)
LOG10(expr)
expr as a doubleLOG10F(expr)
LOG10F(expr)
expr as a floatLOG1P(expr)
LOG1P(expr)
expr as a doubleLOG1PF(expr)
LOG1PF(expr)
expr as a floatLOG2(expr)
LOG2(expr)
expr as a doubleLOG2F(expr)
LOG2F(expr)
expr as a floatLOGF(expr)
LOGF(expr)
LNFMAX_CONSECUTIVE_BITS(expr)
MAX_CONSECUTIVE_BITS(expr)
1 bits in the integer
exprMOD(dividend, divisor)
MOD(dividend, divisor)
dividend by divisorNEXT_AFTER(expr[, target])
NEXT_AFTER(expr[, target])
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)
NEXT_BEFORE(expr)
expr. The return type matches the input (float or double).PI()
PI()
POW(base, exponent)
POW(base, exponent)
POWERPOWF(base, exponent)
POWF(base, exponent)
POWERFPOWER(base, exponent)
POWER(base, exponent)
base raised to the power of exponent as a doublePOWERF(base, exponent)
POWERF(base, exponent)
base raised to the power of exponent as a floatRADIANS(expr)
RADIANS(expr)
expr (in degrees) to radians as a doubleRADIANSF(expr)
RADIANSF(expr)
expr (in degrees) to radians as a floatRAND([seed])
RAND([seed])
seedREGR_VALX(y, x)
REGR_VALX(y, x)
y is NULL; otherwise, returns xREGR_VALY(y, x)
REGR_VALY(y, x)
x is NULL; otherwise, returns yROUND(expr[, scale])
ROUND(expr[, scale])
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 Call | Result |
|---|---|
ROUND(12345.678) | 12346 |
ROUND(12345.678, 2) | 12345.68 |
ROUND(12345.678, 0) | 12346 |
ROUND(12345.678, -2) | 12300 |
SAFE_DIVIDE(a, b)
SAFE_DIVIDE(a, b)
a / b unless b == 0, in which case it returns NULLSIGN(expr)
SIGN(expr)
| Expression Value | Result |
|---|---|
| positive | 1 |
| zero | 0 |
| negative | -1 |
SIN(expr)
SIN(expr)
expr as a doubleSINF(expr)
SINF(expr)
expr as a floatSINH(expr)
SINH(expr)
expr as a doubleSINHF(expr)
SINHF(expr)
expr as a floatSQRT(expr)
SQRT(expr)
expr as a doubleSQRTF(expr)
SQRTF(expr)
expr as a floatTAN(expr)
TAN(expr)
expr as a doubleTANF(expr)
TANF(expr)
expr as a floatTANH(expr)
TANH(expr)
expr as a doubleTANHF(expr)
TANHF(expr)
expr as a floatTRUNCATE(expr[, scale])
TRUNCATE(expr[, scale])
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 Call | Result |
|---|---|
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)
WIDTH_BUCKET(expr, min, max, count)
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 Call | Result |
|---|---|
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)
APPROX_COUNT_DISTINCT(expr)
expr; this is faster to calculate than COUNT_DISTINCT but is only an approximationAPPROX_MEDIAN(expr)
APPROX_MEDIAN(expr)
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)
APPROX_PERCENTILE(expr, p)
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)
AVG(expr)
exprCORR(expr1, expr2)
CORR(expr1, expr2)
expr1 and expr2CORRELATION(expr1, expr2)
CORRELATION(expr1, expr2)
CORRCORRCOEF(expr1, expr2)
CORRCOEF(expr1, expr2)
CORRCOUNT(expr)
COUNT(expr)
expr; use * to count all values within an aggregation group or over an entire tableCOUNT_DISTINCT(expr)
COUNT_DISTINCT(expr)
exprCOV(expr1, expr2)
COV(expr1, expr2)
COVAR_POPCOVAR(expr1, expr2)
COVAR(expr1, expr2)
COVAR_POPCOVARIANCE(expr1, expr2)
COVARIANCE(expr1, expr2)
COVAR_POPCOVAR_POP(expr1, expr2)
COVAR_POP(expr1, expr2)
expr1 and expr2COVAR_SAMP(expr1, expr2)
COVAR_SAMP(expr1, expr2)
expr1 and expr2KURT(expr)
KURT(expr)
KURTOSIS_POPKURTOSIS(expr)
KURTOSIS(expr)
KURTOSIS_POPKURTOSIS_POP(expr)
KURTOSIS_POP(expr)
exprKURTOSIS_SAMP(expr)
KURTOSIS_SAMP(expr)
exprKURT_POP(expr)
KURT_POP(expr)
KURTOSIS_POPKURT_SAMP(expr)
KURT_SAMP(expr)
KURTOSIS_SAMPMAX(expr)
MAX(expr)
exprMEAN(expr)
MEAN(expr)
AVGMIN(expr)
MIN(expr)
exprPRODUCT(expr)
PRODUCT(expr)
exprREGR_AVGX(y, x)
REGR_AVGX(y, x)
SUM(x)/N) of the line determined by computing a least-squares-fit linear regression over the given (X, Y)
pairsREGR_AVGY(y, x)
REGR_AVGY(y, x)
SUM(y)/N) of the line determined by computing a least-squares-fit linear regression over the given (X, Y)
pairsREGR_COUNT(y, x)
REGR_COUNT(y, x)
REGR_INTERCEPT(y, x)
REGR_INTERCEPT(y, x)
REGR_R2(y, x)
REGR_R2(y, x)
REGR_SLOPE(y, x)
REGR_SLOPE(y, x)
REGR_SXX(y, x)
REGR_SXX(y, x)
SUM(x^2) - SUM(x)^2/N) of the line determined by computing a least-squares-fit linear regression
over the given (X, Y) pairsREGR_SXY(y, x)
REGR_SXY(y, x)
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) pairsREGR_SYY(y, x)
REGR_SYY(y, x)
SUM(y^2) - SUM(y)^2/N) of the line determined by computing a least-squares-fit linear regression
over the given (X, Y) pairsSKEW(expr)
SKEW(expr)
SKEWNESS_POPSKEWNESS(expr)
SKEWNESS(expr)
SKEWNESS_POPSKEWNESS_POP(expr)
SKEWNESS_POP(expr)
exprSKEWNESS_SAMP(expr)
SKEWNESS_SAMP(expr)
exprSKEW_POP(expr)
SKEW_POP(expr)
SKEWNESS_POPSKEW_SAMP(expr)
SKEW_SAMP(expr)
SKEWNESS_SAMPSTDDEV(expr)
STDDEV(expr)
expr (i.e. the denominator is N)STDDEV_POP(expr)
STDDEV_POP(expr)
expr (i.e. the denominator is N)STDDEV_SAMP(expr)
STDDEV_SAMP(expr)
expr (i.e. the denominator is N-1)SUM(expr)
SUM(expr)
exprVAR(expr)
VAR(expr)
expr (i.e. the denominator is N)VAR_POP(expr)
VAR_POP(expr)
expr (i.e. the denominator is N)VAR_SAMP(expr)
VAR_SAMP(expr)
expr (i.e. the denominator is N-1)VARIANCE(expr)
VARIANCE(expr)
VARVARIANCE_POP(expr)
VARIANCE_POP(expr)
VAR_POPVARIANCE_SAMP(expr)
VARIANCE_SAMP(expr)
VAR_SAMP