DDSQL Scalar Functions

Join the Beta!

DDSQL is in private beta.

Request Access

These functions return one value per row.

String functions and operators

upper

NameReturn typeDescription
upper(text s)textConverts s to uppercase.

lower

NameReturn typeDescription
lower(text s)textConverts s to lowercase.

length

NameReturn typeDescription
length(text s)integerCounts the number of characters in s.

concat

NameReturn typeDescription
concat(expr x, y, …)textConcatenates the provided expressions.

substr

NameReturn typeDescription
substr(expr s, numeric start, numeric numChars)textReturns a substring of s from start to a max of numChars, if provided. start is a 1-based index, so substr('hello', 2) returns 'ello'. If the start is less than 1, it is treated as if it were 1. The result is computed by taking the range of characters [start, start+numChars], where if any value is less than 1, it is treated as 1. This means substr('hello', -2, 4) returns 'h'.

replace

NameReturn typeDescription
replace(text s, text from, text to)textReplaces all occurrences in s of substring from with substring to.

regexp_replace

NameReturn typeDescription
regexp_replace(text s, text pattern, text replacement)textReplace substrings in s that match the POSIX regular expression pattern with the replacement. Supports Go’s regular expression syntax.

Mathematical functions and operators

abs

NameReturn typeDescription
abs(numeric n)integerReturns the absolute value of n.

round

NameReturn typeDescription
round(numeric n, [s])numericRound n to s decimal places.

mod

NameReturn typeDescription
mod(numeric x, numeric y)integerReturns the remainder of x / y.

floor

NameReturn typeDescription
floor(numeric n)numericReturns the nearest integer that is less than or equal to n.

ceil

NameReturn typeDescription
ceil(numeric n)numericReturns the nearest integer that is greater than or equal to n.

power

NameReturn typeDescription
power(numeric n, numeric s)numericRaises n to the s power.

ln

NameReturn typeDescription
ln(numeric n)numericCalculates the natural logarithm of n.

sqrt

NameReturn typeDescription
sqrt(numeric n)numericCalculates the square root of n.

Date/time functions and operators

date_trunc

NameReturn typeDescription
date_trunc(string precision, timestamp t)timestampTruncates the timestamp to the chosen precision (“second”, “minute”, “hour”, “day”, “week”, “month”, or “year”).

Conditional expressions

coalesce

NameReturn typeDescription
coalesce(expr x, y, …)variableReturns the first non-null expression.

nullif

NameReturn typeDescription
nullif(expr x, expr y)variableReturns NULL if both arguments are equal. Otherwise, returns x.