Skip to main content

Standard Library Reference

Complete listing of the functions defined in the Wvlet standard library, generated from its sources. Call these with dot syntax on a value of the listed type (e.g. name.upper, price.round(2)). See Standard Library Functions for a guided tour with examples.

The Engines column lists the engines a definition is specialized for; all means a single dialect-neutral definition serves every supported engine (DuckDB, Trino, Hive, Snowflake, and BigQuery). Engine-specific SQL is selected automatically for the compile target.

Any Values

Available on values of every type.

FunctionReturnsEnginesDescription
to_stringstringall
to_intintall
to_longlongall
to_floatfloatall
to_doubledoubleall
to_booleanbooleanall
to_datedateallCast to the SQL date type
to_timestamptimestampallCast to the SQL timestamp type
is_nullbooleanallTrue if this value is null
is_not_nullbooleanall
or_else(other: any)anyallReturn the other value if this value is null
null_if(v: any)anyallReturn null if this value equals the given value
type_ofstringallName of the runtime type of this value
to_jsonjsonduckdb, trino

Numeric Values

Shared by all numeric types (int, long, float, real, double, decimal).

FunctionReturnsEnginesDescription
round(decimal: int)doubleallRound to the given number of decimal places
sqrtdoubleall
cbrtdoubleall
expdoubleall
lndoubleall
log10doubleall
log2doubleall
power(exponent: double)doubleall
signintall
in(v: any*)booleanall
not_in(v: any*)booleanall

Int Values

FunctionReturnsEnginesDescription
to_intintall
to_longlongall
to_floatfloatall
to_doubledoubleall
to_booleanbooleanall
to_stringstringall
or_else(other: int)intall
absintall
ceilintall
floorintall
mod(divisor: int)intall
from_unixtimetimestampduckdb, trino, hive, snowflake, bigqueryInterpret this value as a unix epoch second (in UTC)
between(l: int, r: int)booleanall

Long Values

FunctionReturnsEnginesDescription
to_intintall
to_longlongall
to_floatfloatall
to_doubledoubleall
to_booleanbooleanall
to_stringstringall
or_else(other: long)longall
abslongall
ceillongall
floorlongall
mod(divisor: long)longall
from_unixtimetimestampduckdb, trino, hive, snowflake, bigqueryInterpret this value as a unix epoch second (in UTC)
between(l: long, r: long)booleanall
within(duration: string)booleantd_trino
td_time_string(format: string)stringtd_trino, td_hive
td_interval(duration: string)booleantd_hive

Float Values

FunctionReturnsEnginesDescription
to_intintall
to_longlongall
to_floatfloatall
to_doubledoubleall
to_booleanbooleanall
to_stringstringall
or_else(other: float)floatall
absfloatall
ceilfloatall
floorfloatall
is_nanbooleanduckdb, trino, bigquery
is_finitebooleanduckdb, trino, bigquery
is_infinitebooleanduckdb, trino, bigquery
between(l: float, r: float)booleanall

Real Values

FunctionReturnsEnginesDescription
to_intintall
to_longlongall
to_floatfloatall
to_doubledoubleall
to_booleanbooleanall
to_stringstringall
or_else(other: real)realall
absrealall
ceilrealall
floorrealall
between(l: real, r: real)booleanall

Double Values

FunctionReturnsEnginesDescription
to_intintall
to_longlongall
to_floatfloatall
to_doubledoubleall
to_booleanbooleanall
to_stringstringall
or_else(other: double)doubleall
absdoubleall
ceildoubleall
floordoubleall
degreesdoubleall
radiansdoubleall
sindoubleall
cosdoubleall
tandoubleall
asindoubleall
acosdoubleall
atandoubleall
truncatedoubleduckdb, trino, hive, snowflake, bigqueryDrop the fractional part of this value
is_nanbooleanduckdb, trino, bigquery
is_finitebooleanduckdb, trino, bigquery
is_infinitebooleanduckdb, trino, bigquery
between(l: double, r: double)booleanall

Decimal Values

FunctionReturnsEnginesDescription
to_intintall
to_longlongall
to_floatfloatall
to_doubledoubleall
to_booleanbooleanall
to_stringstringall
or_else(other: decimal)decimalall
absdecimalall
ceildecimalall
floordecimalall
mod(divisor: decimal)decimalall
truncatedecimalduckdb, trino, hive, snowflake, bigqueryDrop the fractional part of this value
between(l: decimal, r: decimal)booleanall

Boolean Values

FunctionReturnsEnginesDescription
to_intintall
to_longlongall
to_stringstringall
or_else(other: boolean)booleanallif the value is null, return the given default value

String Values

FunctionReturnsEnginesDescription
to_intintall
to_longlongall
to_floatfloatall
to_doubledoubleall
to_booleanbooleanall
to_datedateall
to_timestamptimestampall
or_else(other: string)stringallif the string is null, return the default value
lengthintallNumber of characters in the string
upperstringall
lowerstringall
trimstringall
ltrimstringall
rtrimstringall
reversestringall
concat(other: string)stringallConcatenate the given string after this string
replace(search: string, replacement: string)stringallReplace all occurrences of the search string with the replacement string
lpad(length: int, pad: string)stringallPad the string to the given length by prepending (lpad) or appending (rpad) the pad string
rpad(length: int, pad: string)stringall
strpos(substr: string)intall1-origin position of the first occurrence of the substring (0 if not found)
like(pattern: string)booleanall
substring(start: int)stringallSubstring from the 1-origin start position (to the end, or of the given length)
substring(start: int, length: int)stringall
regexp_extract(pattern: string)stringallExtract the first substring matching the regular expression
regexp_extract(pattern: string, group_index: int)stringall
starts_with(prefix: string)booleanall
in(v: any*)booleanall
not_in(expr: any*)booleanall
regexp_like(pattern: string)booleanduckdb, trino, hive, snowflake, bigquerySnowflake's REGEXP_LIKE matches the entire string, so use REGEXP_INSTR for the partial-match semantics of the other engines
regexp_replace(pattern: string, replacement: string)stringduckdb, trino, hive, snowflake, bigqueryReplace every substring matching the regular expression with the replacement
contains(substr: string)booleanduckdb, trino, hive, snowflake, bigquery
ends_with(suffix: string)booleanduckdb, trino, hive, snowflake, bigquery
split(separator: string)array[string]duckdb, trino, hive, snowflake, bigquerySplit the string by the separator into an array of strings
md5stringduckdb, trino, hive, snowflake, bigqueryHex-encoded digest strings
sha256stringduckdb, trino, hive, snowflake, bigquery
levenshtein(other: string)intduckdb, trino, hive, snowflake, bigqueryEdit distance between two strings
json_extract(path: string)jsonduckdb, trino, hive, snowflake, bigqueryExtract a JSON value from a string holding JSON text
json_extract_string(path: string)stringduckdb, trino, hive, snowflake, bigquery

Date Values

FunctionReturnsEnginesDescription
extract(field: string)intall
yearintall
monthintall
dayintall
quarterintall
weekintall
or_else(other: date)dateall
truncate_to(unit: string)dateallTruncate to the given unit ('year', 'quarter', 'month', 'week', 'day')
diff_days(other: date)longallDifference between this and the other date, in the given unit
diff_months(other: date)longall
diff_years(other: date)longall
between(l: date, r: date)booleanall
day_of_weekintduckdb, trino, hive, snowflake, bigqueryISO day of week (1 = Monday, 7 = Sunday) and day of year
day_of_yearintduckdb, trino, hive, snowflake, bigquery
add_days(n: int)dateduckdb, trino, hive, snowflake, bigquery
add_months(n: int)dateduckdb, trino, hive, snowflake, bigquery
add_years(n: int)dateduckdb, trino, hive, snowflake, bigquery
format(pattern: string)stringduckdb, trino, hive, snowflake, bigqueryFormat the date with a strftime-style pattern (e.g. '%Y-%m-%d')
last_daydateduckdb, trino, hive, snowflake, bigqueryThe last day of the month of this date

Timestamp Values

FunctionReturnsEnginesDescription
extract(field: string)intall
yearintall
monthintall
dayintall
hourintall
minuteintall
secondintall
quarterintall
weekintall
or_else(other: timestamp)timestampall
to_datedateall
truncate_to(unit: string)timestampallTruncate to the given unit ('year', 'month', 'day', 'hour', 'minute', 'second')
diff_seconds(other: timestamp)longallDifference between this and the other timestamp, in the given unit
diff_minutes(other: timestamp)longall
diff_hours(other: timestamp)longall
diff_days(other: timestamp)longall
between(l: timestamp, r: timestamp)booleanall
day_of_weekintduckdb, trino, hive, snowflake, bigqueryISO day of week (1 = Monday, 7 = Sunday) and day of year
day_of_yearintduckdb, trino, hive, snowflake, bigquery
add_seconds(n: int)timestampduckdb, trino, hive, snowflake, bigqueryTimestamp arithmetic via unix epoch seconds (Hive has no timestamp interval functions)
add_minutes(n: int)timestampduckdb, trino, hive, snowflake, bigquery
add_hours(n: int)timestampduckdb, trino, hive, snowflake, bigquery
add_days(n: int)timestampduckdb, trino, hive, snowflake, bigquery
add_months(n: int)timestampduckdb, trino, snowflake
add_years(n: int)timestampduckdb, trino, snowflake
format(pattern: string)stringduckdb, trino, hive, snowflake, bigqueryFormat the timestamp with a strftime-style pattern (e.g. '%Y-%m-%d %H:%M:%S')
to_unixtimelongduckdb, trino, hive, snowflake, bigqueryUnix epoch seconds of this timestamp
to_stringstringduckdb, trino, hive, snowflake, bigqueryRender as 'YYYY-MM-DD HH:MM:SS'. Overridden per engine so the rendering is identical

JSON Values

FunctionReturnsEnginesDescription
json_extract(path: string)jsonallExtract the JSON value at the JSONPath expression (e.g. '$.store.book')
json_extract_string(path: string)stringduckdb, trinoExtract the value at the JSONPath expression as a plain string

Null Values

FunctionReturnsEnginesDescription
to_intintall
to_longlongall
to_floatfloatall
to_doubledoubleall
to_booleanbooleanall
to_datedateall
to_timestamptimestampall
to_stringstringall

Array Values

A column reference after group by also has an array type, so aggregation functions apply to it with the same syntax.

FunctionReturnsEnginesDescription
lengthintduckdb, trino, hive, snowflake, bigquery
sizeintduckdb, trino, hive, snowflake, bigquery
get(index: int)Aall
countintall
count_distinctintall
count_if(cond: boolean)intall
count_approx_distinctinttrino, duckdb, snowflake, bigqueryFast and memory-efficient approximate counting of distinct elements
arbitraryAall
anyAall
minAall
maxAall
min_by(expr: sql)Aall
max_by(expr: sql)Aall
to_arrayarray[A]all
bool_andbooleanallAggregate boolean values of a grouped column
bool_orbooleanall
string_agg(separator: string)stringduckdb, trino, hive, snowflake, bigqueryConcatenate grouped string values with the separator
exclude(arr: sql)array[A]duckdb, trino
existsbooleanall
not_existsbooleanall
contains(elem: A)booleanallTrue if the array contains the given element
mk_stringstringduckdb, trino, hive, snowflake, bigqueryConcatenate the array elements into a string without a separator
mk_string(separator: string)stringduckdb, trino, hive, snowflake, bigqueryConcatenate the array elements into a string with the separator
distinctarray[A]allRemove duplicate elements
flattenarray[A]allFlatten an array of arrays into a single array
sortarray[A]duckdb, trino, hive, snowflake
reversearray[A]duckdb, trino, snowflake, bigquery
index_of(elem: A)intduckdb, trino, snowflake1-origin position of the first occurrence of the element (0 if not found)
concat(other: any)array[A]duckdb, trino, snowflake, bigquery
lagAallValue of the column at a preceding row of the window
lag(offset: int)Aall
lag(offset: int, default: any)Aall
leadAallValue of the column at a following row of the window
lead(offset: int)Aall
lead(offset: int, default: any)Aall
first_valueAallFirst value of the window
last_valueAallLast value of the window
nth_value(n: int)AallValue at the n-th row (1-origin) of the window
sumAall
avgAall
medianAall
varianceAall
stddevAall
stddev_popAall
stddev_sampAall
var_popAall
var_sampAall
approx_quantile(pos: double)Atrino, duckdb, hive, snowflake, bigquery

Map Values

FunctionReturnsEnginesDescription
sizeintallNumber of entries in the map
keysarray[K]all
valuesarray[V]all
contains_key(key: K)booleanallTrue if the map contains the given key
get(key: K)Vduckdb, trino, hive, snowflakeThe value for the given key, or null if the key is absent

Top-Level Functions

Called without a receiver value (window functions require an over(...) clause).

FunctionReturnsEnginesDescription
ulid_stringstringallGenerate a new ULID
row_numberlongallSequential row number within the window (1, 2, 3, ...)
ranklongallRank with gaps after ties (1, 1, 3, ...)
dense_ranklongallRank without gaps after ties (1, 1, 2, ...)
percent_rankdoubleallRelative rank in [0, 1]: (rank - 1) / (rows - 1)
cume_distdoubleallCumulative distribution in (0, 1]: rows preceding or peer / rows
ntile(n: int)longallBucket number when the window is divided into n groups