Chalk SQL Reference

This reference documents the complete set of Chalk SQL functions for federated queries across data sources, offline stores, and the Chalk catalog.

Returns the absolute value of a number.
Examples
SELECT abs(-42);
| abs(-42) |
| -------- |
| 42       |
Overloads
Calculates the inverse cosine in radians.
Parameters
x:
double
The input value.
Calculates the inverse hyperbolic cosine.
Parameters
x:
double
The input value.
Calculates the inverse hyperbolic sine.
Parameters
x:
double
The input value.
Calculates the inverse hyperbolic tangent.
Parameters
x:
double
The input value.
Calculates the inverse sine in radians.
Parameters
x:
double
The input value.
Calculates the arctangent of a number in radians.
Parameters
x:
double
The input value.
Calculates the arctangent of y/x in radians, handling quadrant correctly.
Parameters
y:
double
The second input value.
x:
double
The input value.
Rounds a number using banker's rounding, optionally to a specified number of decimal places.
Examples
SELECT bankers_round(2.5);
| bankers_round(2.5) |
| ------------------ |
| 2.0                |
SELECT bankers_round(42.125, 2);
| bankers_round(42.125, 2) |
| ------------------------ |
| 42.12                    |
Calculates the cube root of a number.
Examples
SELECT cbrt(27);
| cbrt(27) |
| -------- |
| 3.0      |
Overloads
Alias for ceiling.
Examples
SELECT ceil(42.1);
| ceil(42.1) |
| ---------- |
| 43.0       |
Returns the smallest integer greater than or equal to the given number.
Examples
SELECT ceiling(42.1);
| ceiling(42.1) |
| ------------- |
| 43.0          |
Constrains a value to a minimum and maximum range.
Examples
SELECT clamp(12, 0, 10);
| clamp(12, 0, 10) |
| ---------------- |
| 10               |
Calculates the cosine of an angle in radians.
Parameters
x:
double
The input value.
Calculates the hyperbolic cosine of a number.
Parameters
x:
double
The input value.
Calculates the cotangent of an angle in radians.
Parameters
x:
double
The input value.
Converts radians to degrees.
Parameters
radians:
double
The angle in radians.
Examples
SELECT degrees(pi());
| degrees(pi()) |
| ------------- |
| 180.0         |
Returns the mathematical constant e (Euler's number).
Parameters
None
Calculates e raised to the power of a number.
Parameters
x:
double
The input value.
Returns the largest integer less than or equal to the given number.
Examples
SELECT floor(42.9);
| floor(42.9) |
| ----------- |
| 42.0        |
Checks if a floating-point number is finite (not NaN or infinite).
Parameters
value:
double
The input value.
Checks if a floating-point number is infinite.
Parameters
value:
double
The input value.
Checks if a floating-point number is NaN (Not a Number).
Parameters
value:
double
The input value.
Calculates the natural logarithm of a number.
Parameters
x:
double
The input value.
Calculates the logarithm of a number with a specified or default base.
Examples
SELECT log(10, 100);
| log(10, 100) |
| ------------ |
| 2.0          |
Overloads
Calculates the base-10 logarithm of a number.
Parameters
x:
double
The input value.
Calculates the natural logarithm of (1 + x), accurate for small x.
Parameters
x:
double
The input value.
Calculates the base-2 logarithm of a number.
Parameters
x:
double
The input value.
Returns a floating point NaN (Not a Number) value.
Parameters
None
Returns the negative value of a number.
Returns the mathematical constant π (pi).
Parameters
None
Raises a number to the power of another number.
Parameters
base:
double
The base value.
exponent:
double
The exponent to raise the base to.
Examples
SELECT pow(2.0, 8.0);
| pow(2.0, 8.0) |
| ------------- |
| 256.0         |
Raises the first number to the power of the second number.
Parameters
base:
double
The base value.
exponent:
double
The exponent to raise the base to.
Examples
SELECT power(2.0, 8.0);
| power(2.0, 8.0) |
| --------------- |
| 256.0           |
Converts degrees to radians.
Parameters
degrees:
double
The angle in degrees.
Examples
SELECT radians(180.0);
| radians(180.0)    |
| ----------------- |
| 3.141592653589793 |
Generates a random float between 0 and 1.
Parameters
None
Generates a pseudo-random float or integer.
Examples
SELECT random();
| random()                  |
| ------------------------- |
| <random double in [0, 1)> |
Rounds a floating point number, optionally to a specified number of decimal places.
Examples
SELECT round(42.5);
| round(42.5) |
| ----------- |
| 43.0        |
SELECT round(42.125, 2);
| round(42.125, 2) |
| ---------------- |
| 42.13            |
Rounds a number to n significant figures.
Parameters
value:
double
The input value.
digits:
int64
The number of significant digits to keep.
Returns the sign of a number as -1, 0, or 1.
Examples
SELECT sign(-42);
| sign(-42) |
| --------- |
| -1        |
Overloads
Calculates the sine of an angle in radians.
Parameters
x:
double
The input value.
Calculates the square root of a number.
Parameters
x:
double
The input value.
Examples
SELECT sqrt(144.0);
| sqrt(144.0) |
| ----------- |
| 12.0        |
Calculates the tangent of an angle in radians.
Parameters
x:
double
The input value.
Calculates the hyperbolic tangent of a number.
Parameters
x:
double
The input value.
Truncates a floating-point number, optionally to a specified number of decimal places.
Examples
SELECT truncate(42.987);
| truncate(42.987) |
| ---------------- |
| 42.0             |
SELECT truncate(42.987, 2);
| truncate(42.987, 2) |
| ------------------- |
| 42.98               |
Returns the remainder after dividing the first value by the second.
Examples
SELECT 7 % 3;
| 7 % 3 |
| ----- |
| 1     |
Overloads
Multiplies numeric values, or scales a duration by a numeric value.
Examples
SELECT 6 * 7;
| 6 * 7 |
| ----- |
| 42    |
basic binary ** operation
Parameters
x:
double
The input value.
y:
double
The second input value.
Adds numeric, temporal, or interval values.
Examples
SELECT 2 + 3;
| 2 + 3 |
| ----- |
| 5     |
Subtracts numeric, temporal, or interval values.
Examples
SELECT 7 - 3;
| 7 - 3 |
| ----- |
| 4     |
Negates a numeric value.
Examples
SELECT -42;
| -42 |
| --- |
| -42 |
Overloads
Divides numeric values, or divides a duration by a numeric value.
Examples
SELECT 7.0 / 2.0;
| 7.0 / 2.0 |
| --------- |
| 3.5       |
Overloads
floor division
Overloads
Alias for pow.
Examples
SELECT pow(2.0, 8.0);
| pow(2.0, 8.0) |
| ------------- |
| 256.0         |
Performs logical AND operation on two boolean values.
Parameters
x:
bool
The input value.
y:
bool
The second input value.
Checks if a value is between two bounds (inclusive).

Type parameters. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.

Parameters
value:
$T_ord
The input value. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.
min:
$T_ord
The minimum bound, inclusive. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.
max:
$T_ord
The maximum bound, inclusive. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.
Returns the first non-null value from a list of arguments.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
The first value. T means matching inputs and outputs use the same type.
value2:
$T...
The second value. T means matching inputs and outputs use the same type.
Examples
SELECT coalesce(NULL, 'fallback');
| coalesce(NULL, 'fallback') |
| -------------------------- |
| fallback                   |
Checks if two values are distinct, treating NULL values as different from non-NULL values.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
x:
$T
The input value. T means matching inputs and outputs use the same type.
y:
$T
The second input value. T means matching inputs and outputs use the same type.
Returns whether two values are equal.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT eq(1, 1);
| eq(1, 1) |
| -------- |
| true     |
Returns whether the first value is greater than the second.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT gt(2, 1);
| gt(2, 1) |
| -------- |
| true     |
Returns whether the first value is greater than or equal to the second.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT gte(2, 2);
| gte(2, 2) |
| --------- |
| true      |
Returns the second argument if the condition is true, otherwise returns the third argument.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
The boolean condition to evaluate.
The value returned when the condition is true. T means matching inputs and outputs use the same type.
The value returned when the condition is false. T means matching inputs and outputs use the same type.
Checks if the input is null.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
The input value. T means matching inputs and outputs use the same type.
Returns whether the first value is less than the second.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT lt(1, 2);
| lt(1, 2) |
| -------- |
| true     |
Returns whether the first value is less than or equal to the second.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT lte(2, 2);
| lte(2, 2) |
| --------- |
| true      |
Returns whether two values are not equal.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT neq(1, 2);
| neq(1, 2) |
| --------- |
| true      |
Returns NULL if both arguments compare equal; otherwise returns the first argument.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
The first value. T means matching inputs and outputs use the same type.
The second value. T means matching inputs and outputs use the same type.
Checks if two values are equal, treating NULL values as equal to other NULL values.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
x:
$T
The input value. T means matching inputs and outputs use the same type.
y:
$T
The second input value. T means matching inputs and outputs use the same type.
Checks if two values are not equal, treating NULL values as different from non-NULL values.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
x:
$T
The input value. T means matching inputs and outputs use the same type.
y:
$T
The second input value. T means matching inputs and outputs use the same type.
basic binary != operation

Type parameters. T means matching inputs and outputs use the same type.

Parameters
x:
$T
The input value. T means matching inputs and outputs use the same type.
y:
$T
The second input value. T means matching inputs and outputs use the same type.
basic binary < operation

Type parameters. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.

Parameters
x:
$T_ord
The input value. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.
y:
$T_ord
The second input value. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.
basic binary <= operation

Type parameters. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.

Parameters
x:
$T_ord
The input value. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.
y:
$T_ord
The second input value. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.
Cosine distance (1 - cosine similarity) between two vectors.
Overloads
basic binary == operation

Type parameters. T means matching inputs and outputs use the same type.

Parameters
x:
$T
The input value. T means matching inputs and outputs use the same type.
y:
$T
The second input value. T means matching inputs and outputs use the same type.
basic binary > operation

Type parameters. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.

Parameters
x:
$T_ord
The input value. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.
y:
$T_ord
The second input value. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.
basic binary >= operation

Type parameters. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.

Parameters
x:
$T_ord
The input value. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.
y:
$T_ord
The second input value. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.
Raises an error with the specified error message.
Attempts to execute an expression and handles any errors gracefully.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
The input value. T means matching inputs and outputs use the same type.
Counts the number of bits in `x`.
Parameters
x:
int64
The input value.
bits:
int64
The bit width to operate within.
Performs bitwise AND operation on two integer values.
Returns the arithmetic right shift operation on x in 2’s complement representation. shift must not be negative.
Parameters
x:
int64
The input value.
shift:
int64
Returns the logical right shift operation on x (treated as bits-bit integer) shifted by shift. shift must not be negative.
Parameters
x:
int64
The input value.
shift:
int64
bits:
int64
The bit width to operate within.
Performs bitwise NOT operation (complement) on an integer value.
Performs bitwise OR operation on two integer values.
Returns the left shift operation on x (treated as bits-bit integer) shifted by shift. shift must not be negative.
Parameters
x:
int64
The input value.
shift:
int64
bits:
int64
The bit width to operate within.
Performs bitwise XOR operation on two integer values.
Applies boolean AND or bitwise AND to two values.
Examples
SELECT TRUE & FALSE;
| TRUE & FALSE |
| ------------ |
| false        |
SELECT 6 & 3;
| 6 & 3 |
| ----- |
| 2     |
Overloads
Applies boolean OR or bitwise OR to two values.
Examples
SELECT TRUE | FALSE;
| TRUE \| FALSE |
| ------------- |
| true          |
SELECT 4 | 1;
| 4 \| 1 |
| ------ |
| 5      |
Overloads
Applies boolean NOT or bitwise NOT to a value.
Examples
SELECT ~TRUE;
| ~TRUE |
| ----- |
| false |
Overloads
▲~x
▲~x
▲~x
▲~x
▲~x
▲~x
Returns true if every element of the array satisfies the predicate.

Type parameters. T means matching inputs and outputs use the same type.

Returns true if any element of the array satisfies the predicate.

Type parameters. T means matching inputs and outputs use the same type.

Returns element-wise sum of two arrays.
Examples
SELECT array_add(ARRAY[120.5, 0.0, 42.25, 310.0], ARRAY[15.0, 60.75, 8.0, 0.0]) AS combined_daily_spend;
| combined_daily_spend         |
| ---------------------------- |
| [135.5, 60.75, 50.25, 310.0] |
Returns true if all elements in a boolean array are true.
Examples
SELECT array_all(transform(ARRAY['alice@example.com', 'bob@example.com', 'carol-at-example.com'], e -> strpos(e, '@') > 0)) AS all_emails_valid;
| all_emails_valid |
| ---------------- |
| false            |
SELECT array_all(ARRAY[true, NULL, true]) AS all_true_ignoring_nulls;
| all_true_ignoring_nulls |
| ----------------------- |
| true                    |
Returns true if any element in a boolean array is true.
Examples
SELECT array_any(transform(ARRAY['crypto', 'wire', 'gift card'], k -> strpos(lower('Urgent WIRE transfer to new payee'), k) > 0)) AS memo_is_risky;
| memo_is_risky |
| ------------- |
| true          |
SELECT array_any(ARRAY[false, CAST(NULL AS BOOLEAN), false]) AS any_rule_fired;
| any_rule_fired |
| -------------- |
| false          |
Adds an element to the end of an array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT array_append(ARRAY['login', 'view_cart'], 'checkout') AS session_events;
| session_events               |
| ---------------------------- |
| [login, view_cart, checkout] |
SELECT array_max(array_append(ARRAY[42.50, 18.99, 120.00], 310.75)) AS max_txn_amount_incl_current;
| max_txn_amount_incl_current |
| --------------------------- |
| 310.75                      |
Alias for transform.
Examples
SELECT array_apply(ARRAY['  Groceries', 'FUEL ', 'Dining'], tag -> lower(trim(tag))) AS normalized_tags;
| normalized_tags           |
| ------------------------- |
| [groceries, fuel, dining] |
SELECT array_apply(ARRAY[19.99, 5.0, 120.5], x -> round(x * 1.08, 2)) AS prices_with_tax;
| prices_with_tax      |
| -------------------- |
| [21.59, 5.4, 130.14] |
Returns the index of the maximum element in an array.
Examples
SELECT element_at(ARRAY['groceries', 'travel', 'dining', 'utilities'], array_arg_max(ARRAY[0.12, 0.71, 0.05, 0.12]) + 1) AS predicted_category;
| predicted_category |
| ------------------ |
| travel             |
SELECT array_arg_max(ARRAY[42, 87, NULL, 87, 15]) AS busiest_hour_index;
| busiest_hour_index |
| ------------------ |
| 1                  |
Returns the index of the minimum element in an array.
Examples
SELECT element_at(ARRAY['ups', 'fedex', 'usps', 'dhl'], array_arg_min(ARRAY[412.50, 389.99, 405.00, 395.25]) + 1) AS cheapest_carrier;
| cheapest_carrier |
| ---------------- |
| fedex            |
SELECT array_arg_min(ARRAY[CAST(NULL AS DOUBLE), 0.42, 0.17, 0.88, 0.17]) AS nearest_centroid_idx;
| nearest_centroid_idx |
| -------------------- |
| 2                    |
Calculates the average of numeric values in an array.
Examples
SELECT round(array_average(ARRAY[42.50, 18.99, 120.00, 7.25, 61.30]), 2) AS avg_recent_txn_amount;
| avg_recent_txn_amount |
| --------------------- |
| 50.01                 |
SELECT array_average(ARRAY[4.5, NULL, 5.0, 2.5]) AS avg_review_rating;
| avg_review_rating |
| ----------------- |
| 4.0               |
Removes all null values from an array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT array_compact(ARRAY[CASE WHEN 1250.00 > 1000 THEN 'large_amount' END, CASE WHEN 'US' <> 'BR' THEN 'cross_border' END, CASE WHEN 3 > 5 THEN 'high_velocity' END]) AS triggered_rules;
| triggered_rules              |
| ---------------------------- |
| [large_amount, cross_border] |
SELECT cardinality(array_compact(ARRAY['ada@example.com', NULL, '+1-555-0100', NULL])) AS contact_methods_on_file;
| contact_methods_on_file |
| ----------------------- |
| 2                       |
Creates an array from zero or more values.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT array_constructor(1, 2, 3);
| array_constructor(1, 2, 3) |
| -------------------------- |
| [1, 2, 3]                  |
Alias for contains.
Examples
SELECT array_contains(split(lower('Refund for order 8812 - duplicate charge'), ' '), 'refund') AS memo_mentions_refund;
| memo_mentions_refund |
| -------------------- |
| true                 |
SELECT array_contains(ARRAY[5411, 5812, 7995], 7995) AS has_gambling_mcc;
| has_gambling_mcc |
| ---------------- |
| true             |
Returns true if the array contains the given element.
Examples
SELECT array_contains_element(split(lower('Wire transfer to Crypto exchange'), ' '), 'crypto') AS memo_mentions_crypto;
| memo_mentions_crypto |
| -------------------- |
| true                 |
SELECT array_contains_element(ARRAY[5411, 5812, 5541], 7995) AS used_gambling_mcc;
| used_gambling_mcc |
| ----------------- |
| false             |
Calculates the cumulative sum of numeric values in an array.
Examples
SELECT array_cum_sum(ARRAY[500.00, -120.50, -45.25, 250.00, -80.00]) AS running_balance;
| running_balance                        |
| -------------------------------------- |
| [500.0, 379.5, 334.25, 584.25, 504.25] |
SELECT array_cum_sum(transform(ARRAY[3, 5, NULL, 2], x -> coalesce(x, 0))) AS running_total;
| running_total |
| ------------- |
| [3, 8, 8, 10] |
Returns an array with duplicate elements removed, preserving order.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT array_distinct(ARRAY['card_present', 'online', 'card_present', 'atm', 'online', 'online']) AS distinct_channels;
| distinct_channels           |
| --------------------------- |
| [card_present, online, atm] |
SELECT cardinality(array_distinct(ARRAY['dev_a1', 'dev_b7', 'dev_a1', 'dev_c3', 'dev_b7'])) AS distinct_device_count;
| distinct_device_count |
| --------------------- |
| 3                     |
Returns an array containing only the duplicate elements from the input array.
Examples
SELECT array_duplicates(split('INV-1042,INV-2210,INV-1042,INV-3301,INV-2210,INV-1042', ',')) AS repeated_invoice_ids;
| repeated_invoice_ids |
| -------------------- |
| [INV-1042, INV-2210] |
SELECT cardinality(array_duplicates(ARRAY[4417, 9012, 4417, 3388, 9012, 4417])) AS reused_device_count;
| reused_device_count |
| ------------------- |
| 2                   |
Returns elements from the first array that are not present in the second array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT array_except(ARRAY['electronics', 'books', 'garden', 'toys'], ARRAY['books', 'toys']) AS unexplored_categories;
| unexplored_categories |
| --------------------- |
| [electronics, garden] |
SELECT array_except(ARRAY[412, 205, 412, 309, 205, 118], ARRAY[309, 777]) AS new_merchant_ids;
| new_merchant_ids |
| ---------------- |
| [412, 205, 118]  |
Filters an array using a callback function predicate.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
array:
large_list<item: $T>
The input array or list. T means matching inputs and outputs use the same type.
predicate:
($T) => bool
T means matching inputs and outputs use the same type.
Examples
SELECT array_filter(ARRAY[12.50, -3.00, 249.99, -45.00, 8.75], x -> x < 0) AS refund_amounts;
| refund_amounts |
| -------------- |
| [-3.0, -45.0]  |
SELECT array_filter(split('urgent,billing,,refund,priority:high', ','), t -> t <> '' AND NOT starts_with(t, 'priority:')) AS ticket_tags;
| ticket_tags               |
| ------------------------- |
| [urgent, billing, refund] |
Returns a map of elements to their frequency counts in an array.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
array:
large_list<item: $T>
The input array or list. T means matching inputs and outputs use the same type.
Examples
SELECT array_frequency(ARRAY['card_present','online','online','atm','online']) AS channel_counts;
| channel_counts                       |
| ------------------------------------ |
| {card_present: 1, online: 3, atm: 1} |
SELECT element_at(array_frequency(split(lower('Refund please. I asked for a refund twice and still no refund'), ' ')), 'refund') AS refund_mentions;
| refund_mentions |
| --------------- |
| 3               |
Checks if an array contains duplicate elements.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT array_has_duplicates(ARRAY['dev_a1', 'dev_b7', 'dev_a1', 'dev_c3']) AS reused_device;
| reused_device |
| ------------- |
| true          |
SELECT array_has_duplicates(transform(split('Alice@Example.com,bob@example.com,alice@example.com', ','), e -> lower(e))) AS shared_email;
| shared_email |
| ------------ |
| true         |
Alias for array_position.
Examples
SELECT array_indexof(ARRAY['approved', 'approved', 'declined', 'approved'], 'declined') AS first_decline_attempt;
| first_decline_attempt |
| --------------------- |
| 3                     |
SELECT array_indexof(ARRAY['low', 'medium', 'high', 'urgent'], 'critical') AS priority_rank;
| priority_rank |
| ------------- |
| 0             |
Returns the intersection of two arrays (elements present in both arrays).

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT array_intersect(ARRAY['refund','urgent','billing','shipping'], ARRAY['billing','refund','chargeback']) AS escalation_tags;
| escalation_tags   |
| ----------------- |
| [refund, billing] |
SELECT cardinality(array_intersect(split(lower('Wireless Noise Cancelling Headphones Black'), ' '), split(lower('noise cancelling headphones'), ' '))) AS query_term_matches;
| query_term_matches |
| ------------------ |
| 3                  |
SELECT array_intersect(ARRAY[3, 1, 3, 2], ARRAY[3, 3, 2]) AS shared;
| shared |
| ------ |
| [3, 2] |
Joins array elements into a string using a separator and optional null replacement.

Type parameters. K is the key type of the input map.

Examples
SELECT array_join(array_constructor('a', 'b', 'c'), ',');
| array_join(array_constructor('a', 'b', 'c'), ',') |
| ------------------------------------------------- |
| a,b,c                                             |
Alias for cardinality.
Examples
SELECT array_length(split('refund requested for order 4821 damaged in shipping', ' ')) AS memo_word_count;
| memo_word_count |
| --------------- |
| 8               |
SELECT array_length(array_distinct(ARRAY['US','US','GB','NG','US'])) AS distinct_login_countries;
| distinct_login_countries |
| ------------------------ |
| 3                        |
Returns the maximum element in an array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT array_max(ARRAY[42.50, 18.99, 129.00, 7.25]) AS largest_purchase;
| largest_purchase |
| ---------------- |
| 129.0            |
SELECT array_max(remove_nulls(ARRAY[0.12, NULL, 0.87, 0.45])) AS peak_fraud_score;
| peak_fraud_score |
| ---------------- |
| 0.87             |
SELECT array_max(ARRAY[DATE '2026-03-14', DATE '2026-09-02', DATE '2026-07-21']) AS latest_login_date;
| latest_login_date |
| ----------------- |
| 2026-09-02        |
Calculates the median value of numeric elements in an array.
Examples
SELECT array_median(ARRAY[42.50, 38.00, 2499.99, 45.25, 40.10]) AS median_txn_amount;
| median_txn_amount |
| ----------------- |
| 42.5              |
SELECT array_median(ARRAY[120, 95, 310, 140]) AS median_response_ms;
| median_response_ms |
| ------------------ |
| 130.0              |
SELECT array_median(remove_nulls(ARRAY[4.5, NULL, 3.0, 5.0])) AS median_rating;
| median_rating |
| ------------- |
| 4.5           |
Returns the minimum element in an array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT array_min(ARRAY[42.5, 18.0, 7.25, 63.1]) AS smallest_txn_amount;
| smallest_txn_amount |
| ------------------- |
| 7.25                |
SELECT array_min(ARRAY[TIMESTAMP '2024-03-14 09:12:00', TIMESTAMP '2024-01-02 18:40:00', TIMESTAMP '2024-02-27 07:05:00']) AS first_login_at;
| first_login_at          |
| ----------------------- |
| 2024-01-02 18:40:00 UTC |
Returns all most frequently occurring elements in an array.
Examples
SELECT array_multimode(ARRAY['grocery','fuel','grocery','dining','fuel','travel']) AS top_categories;
| top_categories  |
| --------------- |
| [grocery, fuel] |
SELECT cardinality(array_multimode(ARRAY['card','ach','card','wire','ach'])) > 1 AS has_tied_payment_method;
| has_tied_payment_method |
| ----------------------- |
| true                    |
Returns the number of distinct non-null elements in an array.
Examples
SELECT array_n_unique(ARRAY['US', 'US', 'MX', NULL, 'BR', 'US']) AS distinct_card_countries;
| distinct_card_countries |
| ----------------------- |
| 3                       |
SELECT array_n_unique(split(lower('Refund refund REFUND please'), ' ')) AS distinct_memo_words;
| distinct_memo_words |
| ------------------- |
| 2                   |
Computes the L_p normalization of a Vector.
Examples
SELECT array_normalize(ARRAY[2.0, -1.0, 4.0, 2.0], 2.0) AS unit_embedding;
| unit_embedding        |
| --------------------- |
| [0.4, -0.2, 0.8, 0.4] |
SELECT array_normalize(ARRAY[12.0, 3.0, 0.0, 5.0], 1.0) AS category_spend_share;
| category_spend_share   |
| ---------------------- |
| [0.6, 0.15, 0.0, 0.25] |
Returns the 1-based position of an element in an array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT array_position(array_constructor('a', 'b', 'a'), 'a');
| array_position(array_constructor('a', 'b', 'a'), 'a') |
| ----------------------------------------------------- |
| 1                                                     |
Applies a reduce function to each element in an array and returns the accumulated value.

Type parameters. T means matching inputs and outputs use the same type. U is a second generic value type. V is the value type of the input map.

Parameters
array:
large_list<item: $T>
The input array or list. T means matching inputs and outputs use the same type.
U is a second generic value type.
inputFunction:
($U, $T) => $U
T means matching inputs and outputs use the same type. U is a second generic value type.
outputFunction:
($U) => $V
V is the value type of the input map. U is a second generic value type.
Examples
SELECT array_reduce(ARRAY[0.02, -0.01, 0.03, 0.015], 1.0, (growth, r) -> growth * (1 + r), growth -> round((growth - 1) * 100, 2)) AS cumulative_return_pct;
| cumulative_return_pct |
| --------------------- |
| 5.57                  |
SELECT array_reduce(ARRAY['ok', 'fail', 'fail', 'ok', 'fail', 'fail', 'fail', 'ok'], struct_pack(cur := 0, best := 0), (s, status) -> IF(status = 'fail', struct_pack(cur := s.cur + 1, best := greatest(s.best, s.cur + 1)), struct_pack(cur := 0, best := s.best)), s -> s.best) AS longest_failure_streak;
| longest_failure_streak |
| ---------------------- |
| 3                      |
Reduces an array with Python-style loop control. Lambda returns (new_state, control_code, result), where control_code is 0=normal, 1=return, 2=continue, 3=break. Returns row(final_state, control_code, result|null).

Type parameters. T means matching inputs and outputs use the same type. S is the callback state type. R is the callback result type.

Parameters
array:
large_list<item: $T>
The input array or list. T means matching inputs and outputs use the same type.
The initial accumulator state. S is the callback state type.
function:
($S, $T) => struct<state: $S, control: int64, result: $R>
The callback function applied to the elements. T means matching inputs and outputs use the same type. R is the callback result type. S is the callback state type.
Removes all occurrences of a specified element from an array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT array_remove(split('POS  PURCHASE   ACME COFFEE', ' '), '') AS memo_tokens;
| memo_tokens                   |
| ----------------------------- |
| [POS, PURCHASE, ACME, COFFEE] |
SELECT cardinality(array_remove(ARRAY[42, -1, 17, -1, 8], -1)) AS valid_reading_count;
| valid_reading_count |
| ------------------- |
| 3                   |
Returns the array with elements in reverse order.
Examples
SELECT array_reverse(ARRAY['login', 'view_cart', 'add_payment', 'checkout']) AS events_newest_first;
| events_newest_first                       |
| ----------------------------------------- |
| [checkout, add_payment, view_cart, login] |
SELECT element_at(array_reverse(split('electronics/computers/laptops/gaming', '/')), 1) AS leaf_category;
| leaf_category |
| ------------- |
| gaming        |
Returns a slice from an array, string, or binary value.

Type parameters. E is the element type of the input array or list.

Examples
SELECT array_slice(array_constructor(1, 2, 3, 4), 2, 3);
| array_slice(array_constructor(1, 2, 3, 4), 2, 3) |
| ------------------------------------------------ |
| [2, 3, 4]                                        |
Sorts an array in ascending order, optionally using a key extraction function.

Type parameters. T means matching inputs and outputs use the same type. U is a second generic value type.

Examples
SELECT array_sort(array_constructor(3, 1, 2));
| array_sort(array_constructor(3, 1, 2)) |
| -------------------------------------- |
| [1, 2, 3]                              |
Sorts an array in descending order, optionally using a key extraction function.

Type parameters. T means matching inputs and outputs use the same type. U is a second generic value type.

Examples
SELECT array_sort_desc(array_constructor(3, 1, 2));
| array_sort_desc(array_constructor(3, 1, 2)) |
| ------------------------------------------- |
| [3, 2, 1]                                   |
Calculates the standard deviation of numeric values in an array.
Examples
SELECT round(array_stddev(ARRAY[42.50, 38.75, 45.10, 40.00, 512.99], false), 2) AS txn_amount_stddev;
| txn_amount_stddev |
| ----------------- |
| 188.57            |
SELECT round(array_stddev(ARRAY[1200.0, 1350.0, 1180.0, 1420.0], true), 2) AS daily_spend_sample_stddev;
| daily_spend_sample_stddev |
| ------------------------- |
| 116.44                    |
Calculates the sum of numeric values in an array.
Examples
SELECT array_sum(ARRAY[3, NULL, 0, 5, NULL, 2, 4]) AS logins_last_7_days;
| logins_last_7_days |
| ------------------ |
| 14                 |
SELECT array_sum(transform(ARRAY[2, 1, 3], qty -> qty * 19.99)) AS order_total;
| order_total |
| ----------- |
| 119.94      |
Alias for array_join.
Examples
SELECT array_to_string(array_sort(ARRAY['travel', 'electronics', 'grocery']), '|') AS category_key;
| category_key                 |
| ---------------------------- |
| electronics\|grocery\|travel |
SELECT array_to_string(ARRAY['US', NULL, 'CA'], ',') AS ship_countries;
| ship_countries |
| -------------- |
| US,CA          |
Applies a transformation function to each element in an array and returns a new array.

Type parameters. T means matching inputs and outputs use the same type. U is a second generic value type.

Parameters
array:
large_list<item: $T>
The input array or list. T means matching inputs and outputs use the same type.
function:
($T) => $U
The callback function applied to the elements. T means matching inputs and outputs use the same type. U is a second generic value type.
Examples
SELECT array_transform(ARRAY['  Groceries', 'DINING ', 'Travel'], tag -> lower(trim(tag))) AS normalized_tags;
| normalized_tags             |
| --------------------------- |
| [groceries, dining, travel] |
SELECT array_transform(ARRAY[1200, 45, 8800], amount_cents -> amount_cents >= 5000) AS is_large_txn;
| is_large_txn         |
| -------------------- |
| [false, false, true] |
Alias for array_distinct.
Examples
SELECT array_unique(split('login,view,login,purchase,view,login', ',')) AS distinct_events;
| distinct_events         |
| ----------------------- |
| [login, view, purchase] |
SELECT cardinality(array_unique(ARRAY['US', 'US', 'MX', 'US', 'BR', 'MX'])) AS distinct_card_countries;
| distinct_card_countries |
| ----------------------- |
| 3                       |
Examples
SELECT array_value('electronics', 'books', 'toys') AS categories;
| categories                 |
| -------------------------- |
| [electronics, books, toys] |
SELECT contains(array_value('US', 'CA', 'GB'), upper('ca')) AS is_supported_country;
| is_supported_country |
| -------------------- |
| true                 |
SELECT array_max(array_value(0.12, 0.87, 0.35)) AS max_risk_signal;
| max_risk_signal |
| --------------- |
| 0.87            |
Checks if two arrays have any elements in common.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT arrays_overlap(split(lower('Wire transfer to CRYPTO exchange'), ' '), ARRAY['crypto', 'casino', 'gift']) AS memo_mentions_risky_merchant;
| memo_mentions_risky_merchant |
| ---------------------------- |
| true                         |
SELECT arrays_overlap(ARRAY['electronics', 'gaming'], ARRAY['groceries', 'pharmacy']) AS shares_category;
| shares_category |
| --------------- |
| false           |
Returns a list of the distinct elements of the common elements

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT arrays_union(ARRAY['electronics', 'gift', 'sale'], ARRAY['sale', 'clearance', 'gift']) AS merged_tags;
| merged_tags                          |
| ------------------------------------ |
| [electronics, gift, sale, clearance] |
SELECT cardinality(arrays_union(ARRAY['ios', 'web', 'ios'], ARRAY['web', 'android'])) AS distinct_device_platforms;
| distinct_device_platforms |
| ------------------------- |
| 3                         |
Returns the number of elements in an array or entries in a map.

Type parameters. V is the value type of the input map. K is the key type of the input map.

Examples
SELECT cardinality(array_constructor(1, 2, 3));
| cardinality(array_constructor(1, 2, 3)) |
| --------------------------------------- |
| 3                                       |
Returns all possible combinations of the given size from an array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT combinations(array_sort(array_distinct(ARRAY['laptop','mouse','laptop','usb_hub'])), 2) AS basket_pairs;
| basket_pairs                                           |
| ------------------------------------------------------ |
| [[laptop, mouse], [laptop, usb_hub], [mouse, usb_hub]] |
SELECT transform(combinations(ARRAY['card','wallet','bank'], 2), p -> array_join(p, '+')) AS channel_pairs;
| channel_pairs                         |
| ------------------------------------- |
| [card+wallet, card+bank, wallet+bank] |
Checks if a list contains a specific element.

Type parameters. V is the value type of the input map.

Parameters
array:
large_list<item: $V>
The input array or list. V is the value type of the input map.
The element to search for. V is the value type of the input map.
Examples
SELECT contains(split(lower('Wire transfer for CRYPTO exchange deposit'), ' '), 'crypto') AS memo_mentions_crypto;
| memo_mentions_crypto |
| -------------------- |
| true                 |
SELECT contains(ARRAY[7995, 6051, 4829], 5411) AS is_high_risk_mcc;
| is_high_risk_mcc |
| ---------------- |
| false            |
Returns an element from an array or map.

Type parameters. E is the element type of the input array or list. K is the key type of the input map. V is the value type of the input map.

Examples
SELECT element_at(array_constructor('a', 'b'), 2);
| element_at(array_constructor('a', 'b'), 2) |
| ------------------------------------------ |
| b                                          |
Returns the first element in an array that matches the given predicate function.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT find_first(ARRAY[120.0, 45.5, 980.0, 2500.0, 60.0], x -> x > 500) AS first_large_txn;
| first_large_txn |
| --------------- |
| 980.0           |
SELECT find_first(ARRAY['gmail.com', 'acme-corp.com', 'yahoo.com'], d -> d NOT IN ('gmail.com', 'yahoo.com', 'hotmail.com')) AS work_domain;
| work_domain   |
| ------------- |
| acme-corp.com |
Returns the 1-based index of the first element in an array that matches the given predicate function.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT find_first_index(ARRAY[42.10, 18.75, 1250.00, 9.99, 3400.00], x -> x > 1000) AS first_large_txn_position;
| first_large_txn_position |
| ------------------------ |
| 3                        |
SELECT find_first_index(ARRAY['viewed', 'added_to_cart', 'viewed', 'purchased'], e -> e = 'purchased') AS steps_to_purchase;
| steps_to_purchase |
| ----------------- |
| 4                 |
Flattens a nested array by one level, combining all sub-arrays into a single array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT flatten(ARRAY[ARRAY['electronics', 'audio'], ARRAY['audio', 'accessories'], ARRAY['books']]) AS order_categories;
| order_categories                                |
| ----------------------------------------------- |
| [electronics, audio, audio, accessories, books] |
SELECT flatten(ARRAY[ARRAY[ARRAY[1, 2], ARRAY[3]], ARRAY[ARRAY[4]]]) AS one_level;
| one_level          |
| ------------------ |
| [[1, 2], [3], [4]] |
Returns the largest value from a list of values.

Type parameters. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.

Examples
SELECT greatest(3.0, 7.0, 5.0);
| greatest(3.0, 7.0, 5.0) |
| ----------------------- |
| 7.0                     |
SELECT greatest(3, 7, 5);
| greatest(3, 7, 5) |
| ----------------- |
| 7                 |
Returns the smallest value from a list of values.

Type parameters. T_ord can be any orderable type, such as a number, string, date, timestamp, or boolean.

Examples
SELECT least(3.0, 7.0, 5.0);
| least(3.0, 7.0, 5.0) |
| -------------------- |
| 3.0                  |
SELECT least(3, 7, 5);
| least(3, 7, 5) |
| -------------- |
| 3              |
Alias for transform.
Examples
SELECT list_apply(ARRAY['  Groceries ', 'GAS', 'groceries'], t -> lower(trim(t))) AS normalized_tags;
| normalized_tags             |
| --------------------------- |
| [groceries, gas, groceries] |
SELECT list_apply(ARRAY[12.5, 250.0, 4999.99], amt -> amt > 1000) AS is_large_txn;
| is_large_txn         |
| -------------------- |
| [false, false, true] |
Alias for array_average.
Examples
SELECT list_avg(ARRAY[42.50, 18.99, 120.00, 7.25]) AS avg_txn_amount;
| avg_txn_amount |
| -------------- |
| 47.185         |
SELECT list_avg(ARRAY[4, 5, NULL, 3, 5]) AS avg_review_rating;
| avg_review_rating |
| ----------------- |
| 4.25              |
Alias for concat.
Examples
SELECT list_concat(ARRAY['electronics','laptops'], ARRAY['clearance'], ARRAY['back_to_school']) AS merged_tags;
| merged_tags                                       |
| ------------------------------------------------- |
| [electronics, laptops, clearance, back_to_school] |
SELECT array_max(list_concat(ARRAY[42.50, 18.00, 7.25], ARRAY[310.00, 299.99])) AS max_txn_amount;
| max_txn_amount |
| -------------- |
| 310.0          |
Alias for contains.
Examples
SELECT list_contains(split(lower('Wire transfer to CRYPTO exchange'), ' '), 'crypto') AS memo_mentions_crypto;
| memo_mentions_crypto |
| -------------------- |
| true                 |
SELECT list_contains(ARRAY[5411, 5812, 7995], 7995) AS is_gambling_mcc;
| is_gambling_mcc |
| --------------- |
| true            |
Alias for cardinality.
Examples
SELECT list_count(regexp_split_to_array('Refund request: duplicate charge on order #4821, card ending 1234', ' ')) AS memo_word_count;
| memo_word_count |
| --------------- |
| 10              |
SELECT list_count(array_distinct(ARRAY['electronics', 'gift_card', 'electronics', 'jewelry'])) AS distinct_category_count;
| distinct_category_count |
| ----------------------- |
| 3                       |
Alias for array_distinct.
Examples
SELECT list_distinct(regexp_split(lower('Refund refund REFUND card fee card'), ' ')) AS memo_tokens;
| memo_tokens         |
| ------------------- |
| [refund, card, fee] |
SELECT cardinality(list_distinct(ARRAY['ios', 'web', 'ios', 'android', 'web', 'ios'])) AS distinct_devices;
| distinct_devices |
| ---------------- |
| 3                |
Either:
  • Returns the element at the specified index in a list.
  • Retrieves the value associated with a key from a map.

Type parameters. E is the element type of the input array or list. K is the key type of the input map. V is the value type of the input map.

Examples
SELECT list_extract(split('Amazon Mktplace*2K4LP1 Seattle WA', ' '), 1) AS merchant_token;
| merchant_token |
| -------------- |
| Amazon         |
SELECT list_extract(split('Amazon Mktplace*2K4LP1 Seattle WA', ' '), -1) AS state_code;
| state_code |
| ---------- |
| WA         |
SELECT list_extract(MAP(ARRAY['US', 'CA', 'MX'], ARRAY[0.02, 0.05, 0.11]), 'CA') AS country_risk;
| country_risk |
| ------------ |
| 0.05         |
Filters a list using a callback function predicate.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT list_filter([12.50, 899.00, 3.25, 1450.00, 64.10], amt -> amt > 500) AS large_transactions;
| large_transactions |
| ------------------ |
| [899.0, 1450.0]    |
SELECT list_filter(['wire transfer to acct', 'grocery store', 'crypto exchange deposit', 'coffee'], memo -> memo LIKE '%wire%' OR memo LIKE '%crypto%') AS risky_memos;
| risky_memos                                      |
| ------------------------------------------------ |
| [wire transfer to acct, crypto exchange deposit] |
SELECT cardinality(list_filter(['success', 'failed', 'failed', 'success', 'failed'], status -> status = 'failed')) AS failed_login_count;
| failed_login_count |
| ------------------ |
| 3                  |
Alias for contains.
Examples
SELECT list_has(split(lower('POS PURCHASE ACH REVERSAL 0423'), ' '), 'reversal') AS is_reversal;
| is_reversal |
| ----------- |
| true        |
SELECT list_has(ARRAY[200, 201, 204], 404) AS is_success_status;
| is_success_status |
| ----------------- |
| false             |
Alias for arrays_overlap.
Examples
SELECT list_has_any(['refund', 'chargeback', 'dispute'], split(lower('Customer filed a DISPUTE for order 4412'), ' ')) AS mentions_dispute_term;
| mentions_dispute_term |
| --------------------- |
| true                  |
SELECT list_has_any(['gift_cards', 'crypto', 'wire_transfer'], ['electronics', 'books', 'groceries']) AS has_high_risk_category;
| has_high_risk_category |
| ---------------------- |
| false                  |
Alias for array_intersect.
Examples
SELECT cardinality(list_intersect(split(lower('Refund for DUPLICATE charge, possible fraud'), ' '), ARRAY['refund','chargeback','dispute','duplicate','fraud'])) AS dispute_keyword_hits;
| dispute_keyword_hits |
| -------------------- |
| 3                    |
SELECT list_intersect(ARRAY[101, 205, 205, 330, 412], ARRAY[205, 412, 412, 999]) AS shared_merchant_ids;
| shared_merchant_ids |
| ------------------- |
| [205, 412]          |
Alias for array_max.
Examples
SELECT list_max(ARRAY[42.50, 1299.99, 18.75, 310.00]) AS largest_purchase;
| largest_purchase |
| ---------------- |
| 1299.99          |
SELECT list_max(ARRAY['2026-03-14', '2026-09-30', '2026-07-02']) AS latest_login_date;
| latest_login_date |
| ----------------- |
| 2026-09-30        |
Alias for array_median.
Examples
SELECT list_median([42.5, 18.0, 1250.0, 37.25, 29.99]) AS median_order_amount;
| median_order_amount |
| ------------------- |
| 37.25               |
SELECT list_median([12, 45, 8, 30]) AS median_session_minutes;
| median_session_minutes |
| ---------------------- |
| 21.0                   |
Alias for array_min.
Examples
SELECT list_min(ARRAY[42.50, 18.99, 7.25, 103.00]) AS smallest_txn_amount;
| smallest_txn_amount |
| ------------------- |
| 7.25                |
SELECT list_min(ARRAY[DATE '2026-03-14', DATE '2025-11-02', DATE '2026-01-20']) AS first_order_date;
| first_order_date |
| ---------------- |
| 2025-11-02       |
Alias for array_mode.
Examples
SELECT array_mode(array_constructor(1, 2, 2, 3));
| array_mode(array_constructor(1, 2, 2, 3)) |
| ----------------------------------------- |
| 2                                         |
Examples
SELECT remove_nulls(list_pack(CASE WHEN 950.0 > 500 THEN 'large_amount' END, CASE WHEN 'NG' <> 'US' THEN 'foreign_ip' END, CASE WHEN 2 > 5 THEN 'high_velocity' END)) AS risk_flags;
| risk_flags                 |
| -------------------------- |
| [large_amount, foreign_ip] |
SELECT array_max(list_pack(120.0, 87.5, 342.0, 15.25)) AS max_txn_amount;
| max_txn_amount |
| -------------- |
| 342.0          |
Alias for array_position.
Examples
SELECT list_position(ARRAY['card_present', 'ecommerce', 'atm_withdrawal', 'wire'], 'atm_withdrawal') AS channel_index;
| channel_index |
| ------------- |
| 3             |
SELECT list_position(ARRAY['low', 'medium', 'high', 'critical'], 'unknown') AS severity_rank;
| severity_rank |
| ------------- |
| 0             |
Alias for array_slice.
Examples
SELECT list_slice(ARRAY[12.50, 8.99, 240.00, 15.25, 980.00, 1250.00], -3, -1) AS last_3_txn_amounts;
| last_3_txn_amounts     |
| ---------------------- |
| [15.25, 980.0, 1250.0] |
SELECT list_slice(ARRAY['login','view_item','add_to_cart','view_item','checkout','purchase'], 1, 6, 2) AS every_other_event;
| every_other_event              |
| ------------------------------ |
| [login, add_to_cart, checkout] |
SELECT list_slice('ACCT-2024-00918', 6, 9) AS account_year;
| account_year |
| ------------ |
| 2024         |
Alias for array_sort.
Examples
SELECT list_sort(ARRAY[42.50, NULL, 7.99, 120.00, 15.25]) AS sorted_amounts;
| sorted_amounts                   |
| -------------------------------- |
| [7.99, 15.25, 42.5, 120.0, NULL] |
SELECT slice(list_sort(ARRAY[42.50, 7.99, 120.00, 15.25, 89.00], x -> -x), 1, 3) AS top_3_amounts;
| top_3_amounts       |
| ------------------- |
| [120.0, 89.0, 42.5] |
Alias for array_stddev.
Examples
SELECT round(list_stddev_pop([12.5, 48.0, 9.99, 130.0, 22.75], false), 2) AS txn_amount_stddev;
| txn_amount_stddev |
| ----------------- |
| 44.74             |
SELECT round(list_stddev_pop([12.5, 48.0, 9.99, 130.0, 22.75], true), 2) AS txn_amount_sample_stddev;
| txn_amount_sample_stddev |
| ------------------------ |
| 50.03                    |
Alias for array_sum.
Examples
SELECT list_sum(ARRAY[3, 0, 7, 2]) AS failed_logins_last_4h;
| failed_logins_last_4h |
| --------------------- |
| 12                    |
SELECT list_sum(ARRAY[19.99, NULL, 5.01]) AS cart_total;
| cart_total |
| ---------- |
| 25.0       |
Alias for transform.
Examples
SELECT list_transform(split('  Electronics , HOME_garden,Toys ', ','), t -> lower(trim(t))) AS normalized_tags;
| normalized_tags                  |
| -------------------------------- |
| [electronics, home_garden, toys] |
SELECT list_transform(ARRAY[1299, 450, 8000], cents -> cents / 100.0) AS line_item_dollars;
| line_item_dollars  |
| ------------------ |
| [12.99, 4.5, 80.0] |
Alias for array_distinct.
Examples
SELECT list_unique(split('electronics,books,electronics,toys,books', ',')) AS purchased_categories;
| purchased_categories       |
| -------------------------- |
| [electronics, books, toys] |
SELECT cardinality(list_unique(ARRAY['dev-a1', 'dev-b7', 'dev-a1', 'dev-a1', 'dev-c3'])) AS distinct_devices_used;
| distinct_devices_used |
| --------------------- |
| 3                     |
Examples
SELECT list_value(0.42, 1.0, 3.7) AS score_vector;
| score_vector     |
| ---------------- |
| [0.42, 1.0, 3.7] |
SELECT cardinality(array_distinct(list_value('visa', 'mastercard', 'visa', 'amex'))) AS distinct_card_networks;
| distinct_card_networks |
| ---------------------- |
| 3                      |
Returns all N-grams (contiguous subsequences of length n) from an array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT transform(ngrams(split(lower('WIRE TRANSFER INTL FEE'), ' '), 2), g -> array_join(g, ' ')) AS memo_bigrams;
| memo_bigrams                             |
| ---------------------------------------- |
| [wire transfer, transfer intl, intl fee] |
SELECT contains(ngrams(ARRAY['login', 'reset_password', 'change_email', 'withdraw', 'logout'], 3), ARRAY['reset_password', 'change_email', 'withdraw']) AS has_takeover_pattern;
| has_takeover_pattern |
| -------------------- |
| true                 |
SELECT ngrams(ARRAY['login', 'reset_password', 'change_email'], 5) AS short_session_ngrams;
| short_session_ngrams                    |
| --------------------------------------- |
| [[login, reset_password, change_email]] |
Returns true if no element of the array satisfies the predicate.

Type parameters. T means matching inputs and outputs use the same type.

Returns the element at the specified Python-style index in a list.

Type parameters. E is the element type of the input array or list.

Examples
SELECT python_element_at(split('Home > Electronics > Audio > Headphones', ' > '), -1) AS leaf_category;
| leaf_category |
| ------------- |
| Headphones    |
SELECT python_element_at(ARRAY['login','browse','add_to_cart','checkout'], 0) AS first_event;
| first_event |
| ----------- |
| login       |
Creates a range of integers with Python-like semantics.
Examples
SELECT transform(python_range(0, length('STARBUCKS') - 2), i -> substr('STARBUCKS', i + 1, 3)) AS merchant_trigrams;
| merchant_trigrams                   |
| ----------------------------------- |
| [STA, TAR, ARB, RBU, BUC, UCK, CKS] |
SELECT python_range(90, 0, -30) AS lookback_days;
| lookback_days |
| ------------- |
| [90, 60, 30]  |
Applies a reduce function to each element in an array and returns the accumulated value.

Type parameters. T means matching inputs and outputs use the same type. U is a second generic value type.

Parameters
array:
large_list<item: $T>
The input array or list. T means matching inputs and outputs use the same type.
U is a second generic value type.
inputFunction:
($U, $T) => $U
T means matching inputs and outputs use the same type. U is a second generic value type.
Combines multiple lists element-wise into a list of paired structures with Python semantics.

Type parameters. E is the element type of the input array or list.

Examples
SELECT python_zip(ARRAY['groceries', 'fuel', 'dining', 'travel'], ARRAY[0.42, 0.31]) AS category_shares;
| category_shares                                   |
| ------------------------------------------------- |
| [{f0: groceries, f1: 0.42}, {f0: fuel, f1: 0.31}] |
SELECT transform(python_zip(ARRAY[100, 105, 98, 120], slice(ARRAY[100, 105, 98, 120], 2, 3)), p -> p.f1 - p.f0) AS balance_deltas;
| balance_deltas |
| -------------- |
| [5, -7, 22]    |
Alias for python_range.
Examples
SELECT range(0, 25, 5) AS score_bucket_edges;
| score_bucket_edges |
| ------------------ |
| [0, 5, 10, 15, 20] |
SELECT transform(range(0, 30, 7), d -> date_add('day', -d, DATE '2024-03-31')) AS weekly_lookback_dates;
| weekly_lookback_dates                                                                                                         |
| ----------------------------------------------------------------------------------------------------------------------------- |
| [2024-03-31 00:00:00 UTC, 2024-03-24 00:00:00 UTC, 2024-03-17 00:00:00 UTC, 2024-03-10 00:00:00 UTC, 2024-03-03 00:00:00 UTC] |
SELECT range(10, 0, -3) AS countdown;
| countdown     |
| ------------- |
| [10, 7, 4, 1] |
Removes all null values from an array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT remove_nulls(ARRAY[CASE WHEN 0.92 > 0.8 THEN 'high_risk_score' END, CASE WHEN 'US' <> 'NG' THEN 'geo_mismatch' END, CASE WHEN 3 > 5 THEN 'velocity_spike' END]) AS fired_rules;
| fired_rules                     |
| ------------------------------- |
| [high_risk_score, geo_mismatch] |
SELECT cardinality(remove_nulls(ARRAY['+1-415-555-0100', NULL, 'alice@example.com', NULL])) AS verified_contact_count;
| verified_contact_count |
| ---------------------- |
| 2                      |
Returns an array containing the element repeated count times.

Type parameters. E is the element type of the input array or list.

Parameters
The element to search for. E is the element type of the input array or list.
count:
int32
The number of values to return or repeat.
Examples
SELECT concat(ARRAY['wire', 'refund'], repeat('<pad>', CAST(greatest(0, 4 - cardinality(ARRAY['wire', 'refund'])) AS INTEGER))) AS padded_tokens;
| padded_tokens                |
| ---------------------------- |
| [wire, refund, <pad>, <pad>] |
Generates a sequence of integers with an optional step.
Examples
SELECT sequence(1, 5);
| sequence(1, 5)  |
| --------------- |
| [1, 2, 3, 4, 5] |
Randomly shuffles the elements of an array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT slice(shuffle(ARRAY['sku_101', 'sku_202', 'sku_303', 'sku_404', 'sku_505']), 1, 2) AS sampled_recs;
| sampled_recs       |
| ------------------ |
| [sku_303, sku_101] |
SELECT array_sort(shuffle(ARRAY['sku_303', 'sku_101', 'sku_505', 'sku_202'])) = array_sort(ARRAY['sku_303', 'sku_101', 'sku_505', 'sku_202']) AS is_permutation;
| is_permutation |
| -------------- |
| true           |
Returns a slice of a list starting at the given position for the specified length.

Type parameters. E is the element type of the input array or list.

Examples
SELECT slice(ARRAY['login', 'view_item', 'add_to_cart', 'checkout', 'purchase'], 1, 3) AS first_three_events;
| first_three_events              |
| ------------------------------- |
| [login, view_item, add_to_cart] |
SELECT slice(ARRAY[120.0, 45.5, 300.0, 18.25, 999.99, 62.0], -3, 3) AS last_three_amounts;
| last_three_amounts    |
| --------------------- |
| [18.25, 999.99, 62.0] |
SELECT array_join(slice(split('Wireless Noise Cancelling Over-Ear Headphones with Mic', ' '), 1, 3), ' ') AS title_prefix;
| title_prefix              |
| ------------------------- |
| Wireless Noise Cancelling |
Returns the element at the specified 1-based index in the array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT subscript(split('jane.doe@acme-corp.com', '@'), 2) AS email_domain;
| email_domain  |
| ------------- |
| acme-corp.com |
SELECT subscript(split('/shop/electronics/audio/headphones', '/'), cardinality(split('/shop/electronics/audio/headphones', '/'))) AS leaf_category;
| leaf_category |
| ------------- |
| headphones    |
Applies a transformation function to each element in an array and returns a new array.

Type parameters. T means matching inputs and outputs use the same type. U is a second generic value type.

Examples
SELECT transform(ARRAY['  AMZN Mktp US ', 'Uber *Trip', 'STARBUCKS #1234'], m -> upper(trim(m))) AS merchant_keys;
| merchant_keys                               |
| ------------------------------------------- |
| [AMZN MKTP US, UBER *TRIP, STARBUCKS #1234] |
SELECT transform(ARRAY[12.50, 840.00, 45.10, 2300.00], amt -> CASE WHEN amt >= 500 THEN 'high' ELSE 'normal' END) AS amount_buckets;
| amount_buckets               |
| ---------------------------- |
| [normal, high, normal, high] |
Removes the last n elements from the array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT trim_array(ARRAY['login', 'view_cart', 'checkout', 'heartbeat', 'heartbeat'], 2) AS user_actions;
| user_actions                 |
| ---------------------------- |
| [login, view_cart, checkout] |
SELECT array_average(trim_array(ARRAY[120.0, 95.5, 143.0, 110.25, 18.0], 1)) AS avg_complete_day_spend;
| avg_complete_day_spend |
| ---------------------- |
| 117.1875               |
Combines two lists element-wise into a list of paired structures.

Type parameters. T means matching inputs and outputs use the same type. U is a second generic value type.

Parameters
array1:
large_list<item: $T>
The first input array. T means matching inputs and outputs use the same type.
array2:
large_list<item: $U>
The second input array. U is a second generic value type.
Examples
SELECT zip(ARRAY['amount', 'velocity', 'geo_mismatch'], ARRAY[0.42, 0.31, 0.27]) AS feature_weights;
| feature_weights                                                                  |
| -------------------------------------------------------------------------------- |
| [{f1: amount, f2: 0.42}, {f1: velocity, f2: 0.31}, {f1: geo_mismatch, f2: 0.27}] |
SELECT zip(ARRAY['ord_1001', 'ord_1002', 'ord_1003'], ARRAY[5, 4]) AS order_ratings;
| order_ratings                                                            |
| ------------------------------------------------------------------------ |
| [{f1: ord_1001, f2: 5}, {f1: ord_1002, f2: 4}, {f1: ord_1003, f2: NULL}] |
Combines two lists element-wise using a callback function to transform paired elements.

Type parameters. T means matching inputs and outputs use the same type. U is a second generic value type. R is the callback result type.

Parameters
array1:
large_list<item: $T>
The first input array. T means matching inputs and outputs use the same type.
array2:
large_list<item: $U>
The second input array. U is a second generic value type.
function:
($T, $U) => $R
The callback function applied to the elements. T means matching inputs and outputs use the same type. U is a second generic value type. R is the callback result type.
Examples
SELECT zip_with(ARRAY[2, 1, 3], ARRAY[4.99, 19.50, 2.25], (qty, price) -> qty * price) AS line_totals;
| line_totals        |
| ------------------ |
| [9.98, 19.5, 6.75] |
SELECT zip_with(ARRAY['US', 'GB', 'DE'], ARRAY['US', 'FR'], (billing, shipping) -> billing = shipping) AS country_matches;
| country_matches     |
| ------------------- |
| [true, false, NULL] |
operator alias for list_has_any

Type parameters. E is the element type of the input array or list.

Examples
SELECT split(lower('Wire transfer to Binance via Coinbase'), ' ') && ARRAY['binance','coinbase','kraken'] AS mentions_crypto_exchange;
| mentions_crypto_exchange |
| ------------------------ |
| true                     |
SELECT ARRAY['US','CA'] && ARRAY['KP','IR','SY'] AS ships_to_sanctioned_country;
| ships_to_sanctioned_country |
| --------------------------- |
| false                       |
Finds all matches of a regular expression pattern in a string and returns them as a list.
Parameters
string:
large_string
The input string.
pattern:
large_string
The pattern to match.
Examples
SELECT boost_regexp_findall('[A-Z]{3}-[0-9]{4}', 'Blocked by ENG-1042; see also OPS-0077 and ENG-1190') AS ticket_refs;
| ticket_refs                    |
| ------------------------------ |
| [ENG-1042, OPS-0077, ENG-1190] |
SELECT boost_regexp_findall('[$]([0-9]+[.][0-9]{2})', 'UBER TRIP $23.40 + tip $5.00, refund $12.15') AS amounts;
| amounts              |
| -------------------- |
| [23.40, 5.00, 12.15] |
Searches for the first occurrence of a pattern in a string using the Boyer-Moore algorithm. Returns the 0-based byte offset of the first match, or -1 if not found.
Parameters
string:
large_string
The input string.
substring:
large_string
The substring to search for.
Examples
SELECT transform(ARRAY['REFUND AMAZON MKTPL', 'ACH DEBIT PAYROLL ACME CORP', 'POS REFUND TARGET #1123'], memo -> boyer_moore_search(memo, 'REFUND')) AS refund_offsets;
| refund_offsets |
| -------------- |
| [0, -1, 4]     |
SELECT substr('POS PURCHASE 04/12 WHOLEFDS MKT #10234 AUSTIN TX', boyer_moore_search('POS PURCHASE 04/12 WHOLEFDS MKT #10234 AUSTIN TX', '#') + 2, 5) AS store_number;
| store_number |
| ------------ |
| 10234        |
Converts an integer to its corresponding ASCII character.
Parameters
n:
int64
The Unicode code point to convert to a character.
Examples
SELECT replace('WIRE' || chr(9) || 'ACME CORP' || chr(9) || 'INV-2231', chr(9), ' | ') AS cleaned_memo;
| cleaned_memo                  |
| ----------------------------- |
| WIRE \| ACME CORP \| INV-2231 |
SELECT chr(65 + CAST(floor(0.47 * 5) AS BIGINT)) AS risk_grade;
| risk_grade |
| ---------- |
| C          |
Returns the Unicode code point of the only character of the string.
Examples
SELECT codepoint(substr('Émile Zola', 1, 1)) AS first_letter_codepoint;
| first_letter_codepoint |
| ---------------------- |
| 201                    |
SELECT codepoint(substr('🛒 Grocery run', 1, 1)) > 127 AS memo_starts_non_ascii;
| memo_starts_non_ascii |
| --------------------- |
| true                  |
Concatenates two or more strings or lists.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT concat('feature', '_', 'store');
| concat('feature', '_', 'store') |
| ------------------------------- |
| feature_store                   |
Counts the number of non-overlapping regex matches in a string.
Examples
SELECT count_matches('Refund not received. REFUND requested twice; please refund ASAP', '(?i)\brefund') AS refund_mentions;
| refund_mentions |
| --------------- |
| 3               |
SELECT count_matches('Call me at 415-555-0123 or 415-555-0199, email jo@example.com', '\d{3}-\d{3}-\d{4}') AS phone_numbers;
| phone_numbers |
| ------------- |
| 2             |
Examples
SELECT editdist3('Amazon Mktplace', 'Amazon Marketplace') AS memo_edit_distance;
| memo_edit_distance |
| ------------------ |
| 3                  |
SELECT round(1.0 - editdist3(lower('Jon Smith'), lower('JOHN SMITH')) / CAST(greatest(length('Jon Smith'), length('JOHN SMITH')) AS DOUBLE), 2) AS name_similarity;
| name_similarity |
| --------------- |
| 0.9             |
Checks if a string ends with a specified suffix.
Parameters
string:
large_string
The input string.
substring:
large_string
The substring to search for.
Examples
SELECT ends_with('feature_store', 'store');
| ends_with('feature_store', 'store') |
| ----------------------------------- |
| true                                |
Returns the Hamming distance of string1 and string2, i.e. the number of positions at which the corresponding characters are different. Note that the two strings must have the same length.
Examples
SELECT hamming_distance('paypal.com', 'paypa1.com') AS lookalike_domain_edits;
| lookalike_domain_edits |
| ---------------------- |
| 1                      |
SELECT hamming_distance('1HGCM82633A004352', '1HGCM82633A004325') AS vin_char_mismatches;
| vin_char_mismatches |
| ------------------- |
| 2                   |
Case-insensitive like
Parameters
string:
large_string
The input string.
pattern:
large_string
The pattern to match.
Examples
SELECT ilike('UBER *TRIP HELP.UBER.COM', '%uber%trip%') AS is_rideshare;
| is_rideshare |
| ------------ |
| true         |
SELECT ilike('Order SKU: tsh-blk-m', '%TSH-___-M') AS is_medium_tshirt;
| is_medium_tshirt |
| ---------------- |
| true             |
SELECT 'RE: Refund request for order #4521' ILIKE '%refund%' AS is_refund_ticket;
| is_refund_ticket |
| ---------------- |
| true             |
Alias for strpos.
Examples
SELECT strpos('chalk data', 'data');
| strpos('chalk data', 'data') |
| ---------------------------- |
| 7                            |
Calculates the Jaccard similarity coefficient between two strings based on character sets.
Parameters
string1:
large_string
The first input string.
string2:
large_string
The second input string.
Examples
SELECT round(jaccard_similarity(lower('AMZN Mktp US'), lower('Amazon Marketplace')), 3) AS merchant_name_similarity;
| merchant_name_similarity |
| ------------------------ |
| 0.533                    |
SELECT jaccard_similarity('listen', 'silent') AS anagram_similarity;
| anagram_similarity |
| ------------------ |
| 1.0                |
Calculates the Jaro similarity between two strings.
Parameters
a:
large_string
b:
large_string
Examples
SELECT round(jaro_similarity(lower('Jon Smith'), lower('JOHN SMITH')), 3) AS name_match;
| name_match |
| ---------- |
| 0.967      |
SELECT jaro_similarity(lower(trim('  Katherine Johnson')), lower('CATHERINE JOHNSON')) >= 0.9 AS payee_matches_account_holder;
| payee_matches_account_holder |
| ---------------------------- |
| true                         |
Calculates the Jaro-Winkler distance between two strings.
Parameters
string1:
large_string
The first input string.
string2:
large_string
The second input string.
The Jaro-Winkler prefix scaling factor.
Examples
SELECT round(jaro_winkler_distance(upper(trim('  Jonathon Smyth ')), 'JONATHAN SMITH', 0.1), 4) AS cardholder_name_distance;
| cardholder_name_distance |
| ------------------------ |
| 0.0571                   |
SELECT ARRAY[round(jaro_winkler_distance('MARTHA', 'MARHTA', 0.0), 4), round(jaro_winkler_distance('MARTHA', 'MARHTA', 0.1), 4), round(jaro_winkler_distance('MARTHA', 'MARHTA', 0.25), 4)] AS distance_by_prefix_weight;
| distance_by_prefix_weight |
| ------------------------- |
| [0.0556, 0.0389, 0.0139]  |
Calculates the Jaro-Winkler similarity between two strings.
Examples
SELECT round(jaro_winkler_similarity(lower('Jonathan Smith'), lower('JONATHON SMITH')), 3) AS cardholder_name_match;
| cardholder_name_match |
| --------------------- |
| 0.971                 |
SELECT round(jaro_winkler_similarity(lower('Jonathan Smith'), lower('JONATHON SMITH'), 0.0), 3) AS match_without_prefix_bonus;
| match_without_prefix_bonus |
| -------------------------- |
| 0.952                      |
Searches for the first occurrence of a pattern in a string using the Knuth-Morris-Pratt algorithm. Returns the 0-based byte offset of the first match, or -1 if not found.
Parameters
string:
large_string
The input string.
substring:
large_string
The substring to search for.
Examples
SELECT substr('ACH DEBIT VENMO PAYMENT REF:8841273', knuth_morris_pratt_search('ACH DEBIT VENMO PAYMENT REF:8841273', 'REF:') + 5) AS payment_ref;
| payment_ref |
| ----------- |
| 8841273     |
SELECT knuth_morris_pratt_search(lower('Where is my REFUND for order 5512?'), 'refund') >= 0 AS mentions_refund;
| mentions_refund |
| --------------- |
| true            |
Either:
  • Returns the length of the binary in bytes.
  • Returns the length of a string in characters.
  • Returns the number of elements in a list.

Type parameters. V is the value type of the input map.

Examples
SELECT length('chalk');
| length('chalk') |
| --------------- |
| 5               |
Returns the byte length of a string.
Examples
SELECT len_bytes('Café ☕ order #42') AS memo_bytes;
| memo_bytes |
| ---------- |
| 19         |
SELECT len_bytes('Café ☕ order #42') > length('Café ☕ order #42') AS has_non_ascii;
| has_non_ascii |
| ------------- |
| true          |
Returns the length of a string, binary, array, or map.

Type parameters. V is the value type of the input map.

Examples
SELECT length('chalk');
| length('chalk') |
| --------------- |
| 5               |
SELECT length(array_constructor(1, 2, 3));
| length(array_constructor(1, 2, 3)) |
| ---------------------------------- |
| 3                                  |
Examples
SELECT levenshtein('paypa1-secure.com', 'paypal-secure.com') AS email_domain_edit_distance;
| email_domain_edit_distance |
| -------------------------- |
| 1                          |
SELECT round(1.0 - CAST(levenshtein(lower('AMZN Mktplace'), lower('Amazon Marketplace')) AS DOUBLE) / greatest(length('AMZN Mktplace'), length('Amazon Marketplace')), 3) AS merchant_name_similarity;
| merchant_name_similarity |
| ------------------------ |
| 0.722                    |
Calculates the Levenshtein distance between two strings.
Parameters
string1:
large_string
The first input string.
string2:
large_string
The second input string.
Examples
SELECT levenshtein_distance('Jonathon Smyth', 'Jonathan Smith') AS name_edit_distance;
| name_edit_distance |
| ------------------ |
| 2                  |
SELECT round(1.0 - levenshtein_distance(lower('Acme Corp.'), lower('ACME Corporation')) / greatest(length('Acme Corp.'), length('ACME Corporation')), 3) AS merchant_name_similarity;
| merchant_name_similarity |
| ------------------------ |
| 0.563                    |
Checks if a string matches a pattern using SQL LIKE syntax with wildcards.
Parameters
string:
large_string
The input string.
pattern:
large_string
The pattern to match.
Examples
SELECT like('ACH DEBIT NETFLIX.COM 866-579-7172', '%NETFLIX%') AS is_netflix_charge;
| is_netflix_charge |
| ----------------- |
| true              |
SELECT like('SKU-48210-XL', 'SKU-____-XL') AS matches_sku_format;
| matches_sku_format |
| ------------------ |
| false              |
SELECT like('Save 20% on your next order', '%20#%%', '#') AS mentions_20_pct_off;
| mentions_20_pct_off |
| ------------------- |
| true                |
Calculates the longest common subsequence between two strings.
Parameters
string1:
large_string
The first input string.
string2:
large_string
The second input string.
Examples
SELECT longest_common_subsequence(lower('AMZN MKTP US*2K4'), lower('amazon marketplace')) AS lcs_length;
| lcs_length |
| ---------- |
| 9          |
SELECT round(CAST(longest_common_subsequence(lower('Jonathan Smith'), lower('JON SMITH')) AS DOUBLE) / greatest(length('Jonathan Smith'), length('JON SMITH')), 2) AS name_match_score;
| name_match_score |
| ---------------- |
| 0.64             |
Converts a string to lowercase.
Parameters
string:
large_string
The input string.
Examples
SELECT lower('Chalk');
| lower('Chalk') |
| -------------- |
| chalk          |
Left pads a string or binary value to a target length.
Examples
SELECT lpad('42', 5, '0');
| lpad('42', 5, '0') |
| ------------------ |
| 00042              |
Removes whitespace or specified characters from the left side of a string.
Examples
SELECT ltrim('  chalk');
| ltrim('  chalk') |
| ---------------- |
| chalk            |
Render a Jinja2 template using the provided JSON context via minijinja.
Examples
SELECT minijinja_render('Classify this transaction memo: "{{ memo }}" (amount: ${{ amount }}, merchant: {{ merchant|upper }})', '{"memo": "UBER *TRIP 8XK2", "amount": 23.5, "merchant": "uber"}') AS llm_prompt;
| llm_prompt                                                                        |
| --------------------------------------------------------------------------------- |
| Classify this transaction memo: "UBER *TRIP 8XK2" (amount: $23.5, merchant: UBER) |
SELECT minijinja_render('{% if score >= 0.8 %}HIGH{% elif score >= 0.5 %}MEDIUM{% else %}LOW{% endif %} risk: {{ flags|join(", ") }}', '{"score": 0.86, "flags": ["new_device", "foreign_ip"]}') AS risk_summary;
| risk_summary                      |
| --------------------------------- |
| HIGH risk: new_device, foreign_ip |
Normalizes a string using a Unicode normalization form.
Examples
SELECT normalize('chalk');
| normalize('chalk') |
| ------------------ |
| chalk              |
Returns the byte length of a string or binary value.
Examples
SELECT octet_length('chalk');
| octet_length('chalk') |
| --------------------- |
| 5                     |
Calculates the partial ratio similarity between two strings using fuzzy matching.
Parameters
string1:
large_string
The first input string.
string2:
large_string
The second input string.
Examples
SELECT partial_ratio('starbucks', lower('SQ *STARBUCKS STORE #1234 SEATTLE WA')) AS merchant_match_score;
| merchant_match_score |
| -------------------- |
| 100.0                |
SELECT round(partial_ratio('starbucks', lower('SQ *STARBUKS COFFEE SEATTLE WA')), 1) AS merchant_match_score;
| merchant_match_score |
| -------------------- |
| 88.9                 |
SELECT partial_ratio('starbucks', 'SQ *STARBUCKS STORE #1234 SEATTLE WA') AS case_sensitive_score;
| case_sensitive_score |
| -------------------- |
| 0.0                  |
Alias for starts_with.
Examples
SELECT starts_with('feature_store', 'feature');
| starts_with('feature_store', 'feature') |
| --------------------------------------- |
| true                                    |
Returns true if all characters in the string are alphanumeric and there is at least one character, matching Python's str.isalnum() behavior.
Examples
SELECT transform(ARRAY['SAVE20', 'SAVE-20', 'save 20', ''], code -> python_is_alnum(code)) AS promo_code_is_alnum;
| promo_code_is_alnum         |
| --------------------------- |
| [true, false, false, false] |
SELECT transform(ARRAY['José99', '東京2024', 'x²', 'user_1'], handle -> python_is_alnum(handle)) AS handle_is_alnum;
| handle_is_alnum           |
| ------------------------- |
| [true, true, true, false] |
Returns true if all characters in the string are alphabetic and there is at least one character, matching Python's str.isalpha() behavior.
Examples
SELECT transform(ARRAY['Zoë', 'Ελλάδα', 'O''Brien', 'Mary Ann', 'R2D2', ''], n -> python_is_alpha(n)) AS valid_given_name;
| valid_given_name                         |
| ---------------------------------------- |
| [true, true, false, false, false, false] |
SELECT python_is_alpha(regexp_replace('Jean-Luc O''Néill', '[\s''-]', '')) AS full_name_is_letters;
| full_name_is_letters |
| -------------------- |
| true                 |
Returns true if all characters are digit characters and there is at least one character, matching Python's str.isdigit() behavior.
Examples
SELECT python_is_digit(replace('4111-1111-1111-1111', '-', '')) AS is_numeric_card;
| is_numeric_card |
| --------------- |
| true            |
SELECT transform(ARRAY['94107', '9410A', '-42', '3.14', '', '²'], z -> python_is_digit(z)) AS is_digit_flags;
| is_digit_flags                           |
| ---------------------------------------- |
| [true, false, false, false, false, true] |
Returns true if all cased characters are lowercase and there is at least one cased character, matching Python's str.islower() behavior.
Examples
SELECT transform(ARRAY['refund issued', 'URGENT: Call Me', 'order #48213 shipped', '12345'], s -> python_is_lower(s)) AS is_lower;
| is_lower                   |
| -------------------------- |
| [true, false, true, false] |
Returns true if all characters are numeric characters and there is at least one character, matching Python's str.isnumeric() behavior.
Examples
SELECT CASE WHEN python_is_numeric(split_part('ACH PMT 4471 REF 20240115', ' ', 3)) THEN CAST(split_part('ACH PMT 4471 REF 20240115', ' ', 3) AS BIGINT) END AS payee_id;
| payee_id |
| -------- |
| 4471     |
SELECT transform(ARRAY['94107', '12.50', '-3', '', '½', 'Ⅻ', '٣٤'], s -> python_is_numeric(s)) AS is_numeric;
| is_numeric                                    |
| --------------------------------------------- |
| [true, false, false, false, true, true, true] |
Returns true if all characters are whitespace and there is at least one character, matching Python's str.isspace() behavior.
Examples
SELECT python_is_space(chr(9) || '   ' || chr(13) || chr(10)) AS ticket_body_is_blank;
| ticket_body_is_blank |
| -------------------- |
| true                 |
SELECT transform(ARRAY['  ' || chr(9) || chr(10), '', ' refund pls '], memo -> python_is_space(memo)) AS memo_is_blank;
| memo_is_blank        |
| -------------------- |
| [true, false, false] |
SELECT python_is_space(chr(160) || chr(8195)) AS unicode_space;
| unicode_space |
| ------------- |
| true          |
Returns true if the string is titlecased and there is at least one cased character, matching Python's str.istitle() behavior.
Examples
SELECT transform(ARRAY['Wireless Mouse', 'wireless mouse', 'USB-C Cable', 'iPhone Case', '2024 Model', 'ACME'], t -> python_is_title(t)) AS is_title_case;
| is_title_case                            |
| ---------------------------------------- |
| [true, false, false, false, true, false] |
SELECT CASE WHEN python_is_title('Mary-Jane O''Brien') THEN 'clean' ELSE 'needs_normalization' END AS name_entry_quality;
| name_entry_quality |
| ------------------ |
| clean              |
Returns true if all cased characters are uppercase and there is at least one cased character, matching Python's str.isupper() behavior.
Examples
SELECT python_is_upper('URGENT: REFUND ORDER #4471 NOW!!') AS is_all_caps_ticket;
| is_all_caps_ticket |
| ------------------ |
| true               |
SELECT python_is_upper('4471-0092') AS is_all_caps_ticket;
| is_all_caps_ticket |
| ------------------ |
| false              |
Strips leading Python whitespace (Unicode-aware), matching Python's str.lstrip() with no arguments.
Examples
SELECT starts_with(python_lstrip(chr(160) || chr(9) || ' REFUND: duplicate charge'), 'REFUND') AS is_refund_memo;
| is_refund_memo |
| -------------- |
| true           |
SELECT '[' || python_lstrip(chr(160) || chr(12288) || '  Refund for order #8812  ') || ']' AS cleaned_memo;
| cleaned_memo               |
| -------------------------- |
| [Refund for order #8812  ] |
Removes the prefix from the string if present, matching Python's str.removeprefix().
Examples
SELECT transform(ARRAY['POS DEBIT STARBUCKS #1123', 'ACH PAYROLL ACME INC'], m -> python_remove_prefix(m, 'POS DEBIT ')) AS merchants;
| merchants                               |
| --------------------------------------- |
| [STARBUCKS #1123, ACH PAYROLL ACME INC] |
SELECT python_remove_prefix('Re: Re: Refund request #4821', 'Re: ') AS ticket_subject;
| ticket_subject           |
| ------------------------ |
| Re: Refund request #4821 |
Removes the suffix from the string if present, matching Python's str.removesuffix().
Examples
SELECT python_remove_suffix('Acme Corp Inc.', ' Inc.') AS merchant_name;
| merchant_name |
| ------------- |
| Acme Corp     |
SELECT transform(ARRAY['events_2024.csv', 'events_2025.parquet', 'users.csv'], f -> python_remove_suffix(f, '.csv')) AS table_names;
| table_names                               |
| ----------------------------------------- |
| [events_2024, events_2025.parquet, users] |
Strips trailing Python whitespace (Unicode-aware), matching Python's str.rstrip() with no arguments.
Examples
SELECT '[' || python_rstrip('  UBER *TRIP HELP.UBER.COM' || chr(160) || chr(12288) || chr(13) || chr(10)) || ']' AS cleaned_memo;
| cleaned_memo                 |
| ---------------------------- |
| [  UBER *TRIP HELP.UBER.COM] |
SELECT python_rstrip('Wireless Earbuds' || chr(160)) = 'Wireless Earbuds' AS matches_catalog_title;
| matches_catalog_title |
| --------------------- |
| true                  |
Slices a string with exact Python s[start:stop:step] semantics. All integer arguments are nullable (NULL = Python None / unspecified).
Examples
SELECT python_string_slice('4111111111111111', -4, NULL, NULL) AS card_last4;
| card_last4 |
| ---------- |
| 1111       |
SELECT python_string_slice('2024-03-15T09:30:00Z', 5, -10, NULL) AS month_day;
| month_day |
| --------- |
| 03-15     |
SELECT python_string_slice('A1B2C3D4', 1, NULL, 2) AS digits;
| digits |
| ------ |
| 1234   |
Strips leading and trailing Python whitespace (Unicode-aware), matching Python's str.strip() with no arguments.
Examples
SELECT python_strip(chr(160) || '  Wireless Mouse - Black' || chr(9) || chr(10)) AS product_title;
| product_title          |
| ---------------------- |
| Wireless Mouse - Black |
SELECT python_strip(chr(160) || ' ACME COFFEE ' || chr(9) || chr(10)) = 'ACME COFFEE' AS memo_matches_merchant;
| memo_matches_merchant |
| --------------------- |
| true                  |
SELECT nullif(python_strip(chr(12288) || chr(10) || chr(9) || '  '), '') IS NULL AS is_blank_note;
| is_blank_note |
| ------------- |
| true          |
Returns the first substring matched by a regular expression.
Examples
SELECT regexp_extract('user_123', 'user_([0-9]+)', 1);
| regexp_extract('user_123', 'user_([0-9]+)', 1) |
| ---------------------------------------------- |
| 123                                            |
Returns all substrings matched by a regular expression.
Examples
SELECT regexp_extract_all('a1 b2 c3', '[a-z][0-9]');
| regexp_extract_all('a1 b2 c3', '[a-z][0-9]') |
| -------------------------------------------- |
| [a1, b2, c3]                                 |
Checks if a string matches a regular expression pattern.
Parameters
string:
large_string
The input string.
pattern:
large_string
The pattern to match.
Examples
SELECT regexp_full_match('POS PURCHASE STARBUCKS #4471 SEATTLE WA', '(?i)starbucks|dunkin|peet''s') AS is_coffee_shop;
| is_coffee_shop |
| -------------- |
| true           |
SELECT regexp_full_match('ORD-2024-00981-RETRY', '^ORD-[0-9]{4}-[0-9]{5}$') AS is_valid_order_id;
| is_valid_order_id |
| ----------------- |
| false             |
Checks if a string matches a regular expression pattern.
Parameters
string:
large_string
The input string.
pattern:
large_string
The pattern to match.
Examples
SELECT regexp_like('user_123', '^user_[0-9]+$');
| regexp_like('user_123', '^user_[0-9]+$') |
| ---------------------------------------- |
| true                                     |
Alias for regexp_like.
Examples
SELECT regexp_like('user_123', '^user_[0-9]+$');
| regexp_like('user_123', '^user_[0-9]+$') |
| ---------------------------------------- |
| true                                     |
Replaces or removes substrings matched by a regular expression.
Examples
SELECT regexp_replace('user_123', '[0-9]+', '456');
| regexp_replace('user_123', '[0-9]+', '456') |
| ------------------------------------------- |
| user_456                                    |
Splits ``string`` using the regular expression ``pattern`` into a list of strings.
Parameters
string:
large_string
The input string.
pattern:
large_string
The pattern to match.
Examples
SELECT regexp_split('POS PURCHASE*STARBUCKS #1234  SEATTLE WA', '[\s*#]+') AS memo_tokens;
| memo_tokens                                   |
| --------------------------------------------- |
| [POS, PURCHASE, STARBUCKS, 1234, SEATTLE, WA] |
SELECT cardinality(regexp_split('My order never arrived and support has not replied in 3 days', '\s+')) AS ticket_word_count;
| ticket_word_count |
| ----------------- |
| 12                |
Alias for regexp_split.
Examples
SELECT regexp_split_to_array('ACH DEBIT | PAYROLL;ACME CORP  |ref#88213', '\s*[|;]\s*') AS memo_parts;
| memo_parts                                 |
| ------------------------------------------ |
| [ACH DEBIT, PAYROLL, ACME CORP, ref#88213] |
SELECT cardinality(regexp_split_to_array('Wireless noise-cancelling over-ear headphones', '[\s-]+')) AS title_token_count;
| title_token_count |
| ----------------- |
| 6                 |
Replaces or removes occurrences of a substring.
Examples
SELECT replace('hello chalk', 'hello', 'hi');
| replace('hello chalk', 'hello', 'hi') |
| ------------------------------------- |
| hi chalk                              |
Reverses a string, binary value, or array.

Type parameters. T means matching inputs and outputs use the same type.

Examples
SELECT reverse('chalk');
| reverse('chalk') |
| ---------------- |
| klahc            |
Right pads a string or binary value to a target length.
Examples
SELECT rpad('42', 5, '0');
| rpad('42', 5, '0') |
| ------------------ |
| 42000              |
Removes whitespace or specified characters from the right side of a string.
Examples
SELECT rtrim('chalk  ');
| rtrim('chalk  ') |
| ---------------- |
| chalk            |
Computes the similarity ratio between two strings using sequence matching.
Parameters
string1:
large_string
The first input string.
string2:
large_string
The second input string.
Examples
SELECT round(sequence_matcher_ratio(lower(trim('  Jonathan Smith ')), lower(trim('JONATHAN SMYTH'))), 3) AS payee_name_similarity;
| payee_name_similarity |
| --------------------- |
| 0.929                 |
SELECT round(sequence_matcher_ratio('Jonathan Smith', 'JONATHAN SMITH'), 3) AS raw_ratio;
| raw_ratio |
| --------- |
| 0.214     |
Splits a string by a delimiter, optionally limiting the number of splits.
Examples
SELECT split('a,b,c', ',');
| split('a,b,c', ',') |
| ------------------- |
| [a, b, c]           |
Splits a string by delimiter and returns the part at the specified index (1-based).
Parameters
string:
large_string
The input string.
delimiter:
large_string
The delimiter used to split or join the string.
index:
int64
The index to read.
Examples
SELECT split_part('features.user.id', '.', 2);
| split_part('features.user.id', '.', 2) |
| -------------------------------------- |
| user                                   |
Checks if a string starts with a specified prefix.
Parameters
string:
large_string
The input string.
substring:
large_string
The substring to search for.
Examples
SELECT starts_with('feature_store', 'feature');
| starts_with('feature_store', 'feature') |
| --------------------------------------- |
| true                                    |
Alias for split.
Examples
SELECT element_at(str_split('electronics>computers>laptops', '>'), -1) AS leaf_category;
| leaf_category |
| ------------- |
| laptops       |
SELECT str_split('ERROR: payment failed: card declined', ': ', 2) AS level_and_message;
| level_and_message                      |
| -------------------------------------- |
| [ERROR, payment failed: card declined] |
Alias for regexp_split.
Examples
SELECT str_split_regex('wireless headphones, noise-cancelling;  bluetooth 5.3 |black', '\s*[,;|]\s*') AS product_tags;
| product_tags                                                  |
| ------------------------------------------------------------- |
| [wireless headphones, noise-cancelling, bluetooth 5.3, black] |
SELECT str_split_regex('POS PURCHASE #4821 STARBUCKS STORE 1123', '\s*#\d+\s*')[2] AS merchant_part;
| merchant_part        |
| -------------------- |
| STARBUCKS STORE 1123 |
Alias for split.
Examples
SELECT element_at(string_split('POS PURCHASE*STARBUCKS #1042*SEATTLE WA', '*'), 2) AS merchant_name;
| merchant_name   |
| --------------- |
| STARBUCKS #1042 |
SELECT string_split('DECLINED:card_issuer:Insufficient funds: retry after 24h', ':', 3) AS decline_parts;
| decline_parts                                                |
| ------------------------------------------------------------ |
| [DECLINED, card_issuer, Insufficient funds: retry after 24h] |
Alias for regexp_split.
Examples
SELECT string_split_regex('organic, gluten-free;vegan |  non-gmo', '\s*[,;|]\s*') AS product_tags;
| product_tags                           |
| -------------------------------------- |
| [organic, gluten-free, vegan, non-gmo] |
SELECT element_at(string_split_regex('POS PURCHASE   STARBUCKS #4821   SEATTLE WA', '\s{2,}'), 2) AS merchant_name;
| merchant_name   |
| --------------- |
| STARBUCKS #4821 |
Alias for split.
Examples
SELECT element_at(string_to_array('Electronics > Computers > Laptops', ' > '), -1) AS leaf_category;
| leaf_category |
| ------------- |
| Laptops       |
SELECT string_to_array('POS PURCHASE*STARBUCKS #1234*SEATTLE WA', '*', 2) AS memo_parts;
| memo_parts                                 |
| ------------------------------------------ |
| [POS PURCHASE, STARBUCKS #1234*SEATTLE WA] |
Alias for from_base64.
Examples
SELECT json_extract_scalar(from_utf8(string_to_bytes_base64('eyJldmVudCI6ImNoYXJnZS5zdWNjZWVkZWQiLCJhbW91bnQiOjQyMDB9')), '$.event') AS event_type;
| event_type       |
| ---------------- |
| charge.succeeded |
SELECT length(string_to_bytes_base64('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==')) AS image_num_bytes;
| image_num_bytes |
| --------------- |
| 70              |
Alias for from_hex.
Examples
SELECT string_to_bytes_hex('92ef9352c4a90c97d49718afa80788b91c407e18729a267a16b866d9bf3bc243') = sha256(to_utf8('{"order_id":1042,"amount":59.99}')) AS payload_digest_matches;
| payload_digest_matches |
| ---------------------- |
| true                   |
SELECT from_utf8(string_to_bytes_hex('636172645f7465737465645f3432')) AS decoded_event;
| decoded_event  |
| -------------- |
| card_tested_42 |
Alias for to_utf8.
Examples
SELECT length(string_to_bytes_utf8('Café ☕ München')) AS memo_byte_length;
| memo_byte_length |
| ---------------- |
| 18               |
SELECT to_hex(sha256(string_to_bytes_utf8('user@example.com'))) AS email_sha256;
| email_sha256                                                     |
| ---------------------------------------------------------------- |
| b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514 |
Returns the position of a substring within a string.
Examples
SELECT strpos('chalk data', 'data');
| strpos('chalk data', 'data') |
| ---------------------------- |
| 7                            |
Returns the position of the last matching substring within a string.
Examples
SELECT strrpos('chalk data data', 'data');
| strrpos('chalk data data', 'data') |
| ---------------------------------- |
| 12                                 |
Returns a substring starting at the specified position, optionally with a specified length.
Examples
SELECT substr('feature_store', 9);
| substr('feature_store', 9) |
| -------------------------- |
| store                      |
SELECT substr('feature_store', 1, 7);
| substr('feature_store', 1, 7) |
| ----------------------------- |
| feature                       |
Alias for substr.
Examples
SELECT substr('feature_store', 9);
| substr('feature_store', 9) |
| -------------------------- |
| store                      |
SELECT substr('feature_store', 1, 7);
| substr('feature_store', 1, 7) |
| ----------------------------- |
| feature                       |
Alias for ends_with.
Examples
SELECT ends_with('feature_store', 'store');
| ends_with('feature_store', 'store') |
| ----------------------------------- |
| true                                |
Converts a string to title case.
Examples
SELECT titlecase(trim('  BLUE BOTTLE coffee   ')) AS merchant_name;
| merchant_name      |
| ------------------ |
| Blue Bottle Coffee |
SELECT titlecase('mary-jane o''brien') AS customer_name;
| customer_name     |
| ----------------- |
| Mary-jane O'brien |
Calculates the token set ratio similarity between two strings using fuzzy matching.
Parameters
string1:
large_string
The first input string.
string2:
large_string
The second input string.
Examples
SELECT token_set_ratio(lower('Starbucks Coffee Store 1234 Seattle'), lower('STARBUCKS COFFEE')) AS merchant_match_score;
| merchant_match_score |
| -------------------- |
| 100.0                |
SELECT round(token_set_ratio(lower('Sony WH-1000XM5 Wireless Headphones Black'), lower('Sony WH-1000XM4 Wireless Headphones')), 1) AS title_similarity;
| title_similarity |
| ---------------- |
| 89.5             |
SELECT token_set_ratio('Starbucks Coffee', 'STARBUCKS COFFEE') AS case_sensitive_score;
| case_sensitive_score |
| -------------------- |
| 18.75                |
Calculates the token sort ratio similarity between two strings using fuzzy matching.
Parameters
string1:
large_string
The first input string.
string2:
large_string
The second input string.
Examples
SELECT token_sort_ratio('john a smith', 'smith john a') AS name_match_score;
| name_match_score |
| ---------------- |
| 100.0            |
SELECT token_sort_ratio(lower('Acme Corp Payroll Deposit'), lower('PAYROLL DEPOSIT ACME CORP')) >= 90 AS is_same_payee;
| is_same_payee |
| ------------- |
| true          |
Returns the last N characters of the input string, up to at most the length of string.
Examples
SELECT concat('**** **** **** ', trail('4111 1111 1111 4242', 4)) AS masked_card;
| masked_card         |
| ------------------- |
| **** **** **** 4242 |
SELECT trail('MX', 5) AS short_code_tail;
| short_code_tail |
| --------------- |
| MX              |
Removes whitespace or specified characters from both ends of a string.
Examples
SELECT trim('  chalk  ');
| trim('  chalk  ') |
| ----------------- |
| chalk             |
SELECT trim('xychalkyx', 'xy');
| trim('xychalkyx', 'xy') |
| ----------------------- |
| chalk                   |
Normalizes Unicode characters to their closest ASCII equivalents with whitespace normalization.
Parameters
string:
large_string
The input string.
Converts Unicode characters to their closest ASCII equivalents.
Parameters
string:
large_string
The input string.
Converts a string to uppercase.
Parameters
string:
large_string
The input string.
Examples
SELECT upper('chalk');
| upper('chalk') |
| -------------- |
| CHALK          |
Generates a UUID string: a random version 4 UUID with no arguments, or the deterministic version 5 UUID of a name within a namespace UUID with two arguments.
Examples
SELECT uuid_string();
SELECT uuid_string('fe971b24-9572-4005-b22f-351e9c09274d', 'chalk');
Returns the stem of a word using stemming algorithms.
Examples
SELECT array_join(transform(split(lower('Customer requested refunds after charges were disputed'), ' '), w -> word_stem(w)), ' ') AS stemmed_memo;
| stemmed_memo                                  |
| --------------------------------------------- |
| custom request refund after charg were disput |
SELECT word_stem('Zahlungen', 'de') AS stem_de;
| stem_de |
| ------- |
| zahlung |
Left-pads a string with zeros to the given width.
Examples
SELECT zfill(CAST(2134 AS VARCHAR), 5) AS zip_code;
| zip_code |
| -------- |
| 02134    |
SELECT zfill('-42', 6) AS signed_offset;
| signed_offset |
| ------------- |
| -00042        |
Splits a string by delimiter and returns the part at the specified zero-based index.
Parameters
string:
large_string
The input string.
delimiter:
large_string
The delimiter used to split or join the string.
index:
int64
The index to read.
Examples
SELECT lower(zi_split_part('Jane.Doe@Example.COM', '@', 1)) AS email_domain;
| email_domain |
| ------------ |
| example.com  |
SELECT zi_split_part('POS 4821 STARBUCKS #1123 SEATTLE WA', ' ', 2) AS merchant;
| merchant  |
| --------- |
| STARBUCKS |
SELECT coalesce(zi_split_part('electronics>audio', '>', 2), 'none') AS third_level_category;
| third_level_category |
| -------------------- |
| none                 |
operator alias for not like
Parameters
string:
large_string
The input string.
pattern:
large_string
The pattern to match.
Examples
SELECT lower('REFUND - Order #48213') !~~ 'refund%' AS is_purchase;
| is_purchase |
| ----------- |
| false       |
SELECT 'SKU-A1-RED' !~~ 'SKU-___-%' AS bad_sku_format;
| bad_sku_format |
| -------------- |
| true           |
operator alias for not ilike
Parameters
string:
large_string
The input string.
pattern:
large_string
The pattern to match.
Examples
SELECT 'Hi, I need a REFUND for order 88123' !~~* '%refund%' AS is_not_refund_request;
| is_not_refund_request |
| --------------------- |
| false                 |
SELECT 'promo10' !~~* 'PROMO__' AS fails_promo_code_format;
| fails_promo_code_format |
| ----------------------- |
| false                   |
Alias for starts_with.
Examples
SELECT starts_with('feature_store', 'feature');
| starts_with('feature_store', 'feature') |
| --------------------------------------- |
| true                                    |
Alias for concat.
Examples
SELECT 'MERCH-' || upper('acme coffee') || '-' || CAST(42 AS VARCHAR) AS merchant_key;
| merchant_key         |
| -------------------- |
| MERCH-ACME COFFEE-42 |
SELECT 'Title: ' || 'Wireless Earbuds' || ' | Brand: ' || coalesce(NULL, 'unknown') AS embedding_input;
| embedding_input                           |
| ----------------------------------------- |
| Title: Wireless Earbuds \| Brand: unknown |
operator alias for like
Parameters
string:
large_string
The input string.
pattern:
large_string
The pattern to match.
Examples
SELECT 'POS PURCHASE STARBUCKS #1234 SEATTLE WA' ~~ '%STARBUCKS%' AS is_coffee_purchase;
| is_coffee_purchase |
| ------------------ |
| true               |
SELECT lower('Pos Purchase STARBUCKS #1234') ~~ '%starbucks%' AS is_coffee_purchase;
| is_coffee_purchase |
| ------------------ |
| true               |
SELECT 'ORD-2024-A7' ~~ 'ORD-____-__' AS is_valid_order_id;
| is_valid_order_id |
| ----------------- |
| true              |
Case-insensitive like
Parameters
string:
large_string
The input string.
pattern:
large_string
The pattern to match.
Examples
SELECT 'Payment to UBER *TRIP 8821' ~~* '%uber%trip%' AS is_rideshare;
| is_rideshare |
| ------------ |
| true         |
SELECT 'sku-ab12-RED' ~~* 'SKU-__12-%' AS is_ab12_family;
| is_ab12_family |
| -------------- |
| true           |
Returns the current date.
Parameters
None
Converts a timestamp or string to a date.
Examples
SELECT date('2024-01-02');
| date('2024-01-02') |
| ------------------ |
| 2024-01-02         |
Adds a duration or time-unit interval to a date or timestamp.
Examples
SELECT date_add('day', 7, TIMESTAMP '2024-01-02 00:00:00');
| date_add('day', 7, TIMESTAMP '2024-01-02 00:00:00') |
| --------------------------------------------------- |
| 2024-01-09 00:00:00                                 |
Truncates a timestamp onto a fixed-width grid of `bucket_width_seconds`, anchored at `origin_seconds` (seconds since the Unix epoch).
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Returns the difference between two timestamps in the specified unit.
Parameters
unit:
large_string
The time unit, such as 'second', 'day', or 'month'.
timestamp1:
timestamp[us, tz=UTC]
The first timestamp.
timestamp2:
timestamp[us, tz=UTC]
The second timestamp.
Formats a timestamp as a string using the specified format.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
format:
large_string
The format string.
Truncates a timestamp to the specified time unit (e.g., day, month, year).
Parameters
unit:
large_string
The time unit, such as 'second', 'day', or 'month'.
x:
timestamp[us, tz=UTC]
The input value.
Extracts the day of the month from a date or timestamp.
Overloads
Extracts the day of the month from a timestamp.
Extracts the day of the week from a timestamp.
Extracts the day of the month from a timestamp.
Returns the number of days in the month of the given date.
Extracts the day of the week from a date or timestamp.
Overloads
Extracts the day of the year from a date or timestamp.
Overloads
Constructs a duration from a microsecond count.
Parameters
The number of microseconds.
Formats a datetime using a specified format string.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
format:
large_string
The format string.
Formats a UTC timestamp as a string using a Joda format pattern in the given IANA timezone.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
format:
large_string
The format string.
timezone:
large_string
The IANA timezone name, such as 'America/New_York'.
Parses an ISO 8601 date string into a date value.
Parameters
string:
large_string
The input string.
Parses an ISO 8601 timestamp string into a datetime object.
Parameters
string:
large_string
The input string.
Converts a UNIX timestamp to a timestamp, optionally with a time zone offset.
Examples
SELECT from_unixtime(1700000000);
| from_unixtime(1700000000) |
| ------------------------- |
| 2023-11-14 22:13:20 UTC   |
Extracts the hour from a timestamp.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Extracts the hour from a timestamp on a given timezone.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
timezone:
large_string
The IANA timezone name, such as 'America/New_York'.
Returns true if the date falls on a weekday (Monday-Friday).
Returns True if the given timestamp is a federal holiday.
Returns the last day of the month for a given date.
Parameters
date:
timestamp[us, tz=UTC]
The input date or timestamp.
Constructs a date from year, month, and day fields.
Parameters
year:
int64
month:
int64
day:
int64
Extracts the millisecond from a timestamp.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Extracts the minute from a timestamp.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Extracts the month from a timestamp.
Constructs a month/day/nanosecond interval from its three components.
Parameters
months:
int64
days:
int64
The number of days.
nanos:
int64
Converts an ISO 8601 string into a datetime.
Parameters
string:
large_string
The input string.
format:
large_string
The format string.
Extracts the quarter of the year from a timestamp.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Extracts the second from a timestamp.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Constructs a duration with the given number of days.
Constructs a duration with the given number of hours.
Converts a datetime to an ISO 8601 string format.
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Examples
SELECT to_iso8601(TIMESTAMP '2024-01-02 03:04:05');
| to_iso8601(TIMESTAMP '2024-01-02 03:04:05') |
| ------------------------------------------- |
| 2024-01-02T03:04:05.000000Z                 |
Converts a duration to microseconds or constructs a duration from microseconds.
Converts a duration to milliseconds or constructs a duration from milliseconds.
Constructs a duration with the given number of minutes.
Constructs an interval with the given number of months.
Constructs a duration with the given number of seconds.
Converts a timestamp or date to nanoseconds since the Unix epoch (UTC). Throws if the value falls outside the int64 ns range (~1677 to ~2262).
Converts a timestamp to Unix timestamp (seconds since epoch).
Parameters
timestamp:
timestamp[us, tz=UTC]
The input timestamp.
Constructs an interval with the given number of years.
Returns the length of the input duration in seconds.
Parameters
duration:
duration[us]
The input duration.
Extracts the week of the year from a timestamp.
Extracts the week of the year from a timestamp.
Extracts the year from a timestamp.
Extracts the year of the ISO week from a date.
Extracts the year of the ISO week from a date.
Overloads
Returns true if all keys in the map match the given predicate.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
($K) => bool
The map key to read or update. K is the key type of the input map.
Returns true if any key in the map matches the given predicate.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
($K) => bool
The map key to read or update. K is the key type of the input map.
Returns true if any value in the map matches the given predicate.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
($V) => bool
The map key to read or update. V is the value type of the input map.
Checks if a map contains any keys that match a given condition.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
($k) => bool
The map key to read or update.
Filters the entries of a map using a callback predicate.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
($K, $V) => bool
The map key to read or update. K is the key type of the input map. V is the value type of the input map.
Creates a map from separate arrays of keys and values.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Retrieves a value from a map by key.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Checks if a map contains any keys that match a given condition.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
$K
The map key to read or update. K is the key type of the input map.
Returns all keys from a map as a list.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
Returns the keys of a map ordered by their top N highest values.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
int64
The map key to read or update.
Returns a subset of a map containing only the specified keys.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Returns the top N entries from a map ordered by value.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
int64
The map key to read or update.
Returns the top N keys from a map ordered by their values.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
int64
The map key to read or update.
Returns the top N values from a map ordered by value.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
int64
The map key to read or update.
Returns all values from a map as a list.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
Merges two maps by applying a function to each matched key and pair of values.

Type parameters. K is the key type of the input map.

Parameters
map:
map<$K, $V1>
The input map. K is the key type of the input map.
key:
map<$K, $V2>
The map key to read or update. K is the key type of the input map.
function:
($K, $V1, $V2) => $V3
The callback function applied to the elements. K is the key type of the input map.
Returns true if no keys in the map match the given predicate.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
($K) => bool
The map key to read or update. K is the key type of the input map.
Returns true if no values in the map match the given predicate.

Type parameters. K is the key type of the input map. V is the value type of the input map.

Parameters
map:
map<$K, $V>
The input map. K is the key type of the input map. V is the value type of the input map.
key:
($V) => bool
The map key to read or update. V is the value type of the input map.
Returns a map with keys transformed by the given function.

Type parameters. V is the value type of the input map.

Parameters
map:
map<$K1, $V>
The input map. V is the value type of the input map.
key:
($K1, $V) => $K2
The map key to read or update. V is the value type of the input map.
Returns a map with values transformed by the given function.

Type parameters. K is the key type of the input map.

Parameters
map:
map<$K, $V1>
The input map. K is the key type of the input map.
key:
($K, $V1) => $V2
The map key to read or update. K is the key type of the input map.
Compute the Beta cdf with given a, b parameters: P(N < value; a, b). The a, b parameters must be positive real numbers and value must be a real value (all of type DOUBLE). The value must lie on the interval [0, 1].
Parameters
a:
double
b:
double
value:
double
The input value.
Compute the Binomial cdf with given numberOfTrials and successProbability (for a single trial): P(N < value). The successProbability must be real value in [0, 1], numberOfTrials and value must be positive integers with numberOfTrials greater or equal to value.
Parameters
value:
int64
The input value.
Compute the Cauchy cdf with given parameters median and scale (gamma): P(N; median, scale). The scale parameter must be a positive double. The value parameter must be a double on the interval [0, 1].
Parameters
median:
double
scale:
double
value:
double
The input value.
Compute the Chi-square cdf with given df (degrees of freedom) parameter: P(N < value; df). The df parameter must be a positive real number, and value must be a non-negative real value (both of type DOUBLE).
Parameters
df:
double
value:
double
The input value.
Reads the estimated distinct count off a CPC sketch, rounded to the nearest integer.
Unions CPC sketches into a single sketch. Null arguments are skipped; all-null input yields null.
Compute the F cdf with given df1 (numerator degrees of freedom) and df2 (denominator degrees of freedom) parameters: P(N < value; df1, df2). The numerator and denominator df parameters must be positive real numbers. The value must be a non-negative real number.
Parameters
df1:
double
df2:
double
value:
double
The input value.
Compute the Gamma cdf with given shape and scale parameters: P(N < value; shape, scale). The shape and scale parameters must be positive real numbers. The value must be a non-negative real number.
Parameters
shape:
double
scale:
double
value:
double
The input value.
Compute the inverse of the Beta cdf with given a, b parameters for the cumulative probability (p): P(N < n). The a, b parameters must be positive double values. The probability p must lie on the interval [0, 1].
Parameters
a:
double
b:
double
p:
double
Compute the inverse of the Binomial cdf with given numberOfTrials and successProbability (of a single trial) the cumulative probability (p): P(N <= n). The successProbability and p must be real values in [0, 1] and the numberOfTrials must be a positive integer.
Parameters
p:
double
Compute the inverse of the Cauchy cdf with given parameters median and scale (gamma) for the probability p. The scale parameter must be a positive double. The probability p must be a double on the interval [0, 1].
Parameters
median:
double
scale:
double
p:
double
Compute the inverse of the Chi-square cdf with given df (degrees of freedom) parameter for the cumulative probability (p): P(N < n). The df parameter must be positive real values. The probability p must lie on the interval [0, 1].
Parameters
df:
double
p:
double
Compute the inverse of the Fisher F cdf with a given df1 (numerator degrees of freedom) and df2 (denominator degrees of freedom) parameters for the cumulative probability (p): P(N < n). The numerator and denominator df parameters must be positive real numbers. The probability p must lie on the interval [0, 1].
Parameters
df1:
double
df2:
double
p:
double
Compute the inverse of the Laplace cdf with given mean and scale parameters for the cumulative probability (p): P(N < n). The mean must be a real value and the scale must be a positive real value (both of type DOUBLE). The probability p must lie on the interval [0, 1].
Parameters
mean:
double
scale:
double
p:
double
Compute the inverse of the Normal cdf with given mean and standard deviation (sd) for the cumulative probability (p): P(N < n). The mean must be a real value and the standard deviation must be a real and positive value (both of type DOUBLE). The probability p must lie on the interval (0, 1).
Parameters
mean:
double
sd:
double
p:
double
Compute the inverse of the Poisson cdf with given lambda (mean) parameter for the cumulative probability (p). It returns the value of n so that: P(N <= n; lambda) = p. The lambda parameter must be a positive real number (of type DOUBLE). The probability p must lie on the interval [0, 1).
Parameters
lambda:
double
p:
double
Compute the inverse of the Weibull cdf with given parameters a, b for the probability p. The a, b parameters must be positive double values. The probability p must be a double on the interval [0, 1].
Parameters
a:
double
b:
double
p:
double
Compute the Laplace cdf with given mean and scale parameters: P(N < value; mean, scale). The mean and value must be real values and the scale parameter must be a positive value (all of type DOUBLE).
Parameters
mean:
double
scale:
double
value:
double
The input value.
Compute the Normal cdf with given mean and standard deviation (sd): P(N < value; mean, sd). The mean and value must be real values and the standard deviation must be a real and positive value (all of type DOUBLE).
Parameters
mean:
double
sd:
double
value:
double
The input value.
Compute the Poisson cdf with given lambda (mean) parameter: P(N <= value; lambda). The lambda parameter must be a positive real number (of type DOUBLE) and value must be a non-negative integer.
Parameters
lambda:
double
value:
int32
The input value.
Compute the Weibull cdf with given parameters a, b: P(N <= value). The a and b parameters must be positive doubles and value must also be a double.
Parameters
a:
double
b:
double
value:
double
The input value.
Returns the bucket number for a value in a histogram with uniform bucket widths.
Parameters
x:
double
The input value.
bound1:
double
bound2:
double
n:
int64
The number of equal-width buckets.
Returns the lower bound of the Wilson score interval of a Bernoulli trial process at a confidence specified by the z-score z.
Parameters
The number of successes.
trials:
int64
The number of trials.
z:
double
The z-score for the confidence level.
Returns the upper bound of the Wilson score interval of a Bernoulli trial process at a confidence specified by the z-score z.
Parameters
The number of successes.
trials:
int64
The number of trials.
z:
double
The z-score for the confidence level.
Converts an arbitrary json-compatible value into json.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
The input value. T means matching inputs and outputs use the same type.
Examples
SELECT cast_to_json({'merchant': 'Blue Bottle', 'amount': 4.5, 'tags': ['coffee', 'recurring']}) AS txn_json;
| txn_json                                                              |
| --------------------------------------------------------------------- |
| {"amount":4.5,"merchant":"Blue Bottle","tags":["coffee","recurring"]} |
SELECT cast_to_json('{"merchant": "Blue Bottle"}') AS memo_json;
| memo_json                             |
| ------------------------------------- |
| "{\\"merchant\\": \\"Blue Bottle\\"}" |
Alias for json_extract.
Examples
SELECT get_json_value('{"customer": {"id": 4821, "tier": "gold"}, "items": [{"sku": "A-100", "qty": 2}]}', '$.customer.tier') AS customer_tier;
| customer_tier |
| ------------- |
| "gold"        |
SELECT get_json_value('{"order_id": "ord_771", "items": [{"sku": "A-100", "qty": 2}, {"sku": "B-205", "qty": 1}]}', '$.items[*].sku') AS order_skus;
| order_skus        |
| ----------------- |
| ["A-100","B-205"] |
SELECT CAST(get_json_value('{"txn": {"amount": 129.99, "currency": "USD"}}', '$.txn.amount') AS DOUBLE) * 100 AS amount_cents;
| amount_cents |
| ------------ |
| 12999.0      |
Extracts a value from JSON or a JSON string using a path expression and records invalid JSON errors.
Examples
SELECT get_json_value_strict('{"merchant": {"name": "Blue Bottle Coffee", "mcc": "5814"}, "amount": 6.25}', '$.merchant.mcc') AS merchant_mcc;
| merchant_mcc |
| ------------ |
| "5814"       |
SELECT CAST(get_json_value_strict('{"order_id": "ord_918", "items": [{"sku": "A1", "qty": 2}, {"sku": "B7", "qty": 1}], "total_cents": 4598}', '$.items[0].qty') AS BIGINT) AS first_item_qty;
| first_item_qty |
| -------------- |
| 2              |
SELECT coalesce(CAST(get_json_value_strict('{"user_id": 42, "device": {"os": "ios"}}', '$.device.browser', false) AS VARCHAR), 'unknown') AS device_browser;
| device_browser |
| -------------- |
| unknown        |
Returns whether a JSON value or JSON string represents a scalar.
Examples
SELECT transform(ARRAY['{"merchant": "Acme Grocery"}', '{"merchant": {"name": "Blue Bottle", "mcc": 5814}}'], p -> CASE WHEN is_json_scalar(json_extract(p, '$.merchant')) THEN json_extract_scalar(p, '$.merchant') ELSE json_extract_scalar(p, '$.merchant.name') END) AS merchant_name;
| merchant_name               |
| --------------------------- |
| [Acme Grocery, Blue Bottle] |
SELECT transform(ARRAY['42', '"refund"', 'true', 'null', '[1,2]', '{"a":1}'], x -> is_json_scalar(x)) AS is_scalar;
| is_scalar                              |
| -------------------------------------- |
| [true, true, true, true, false, false] |
Checks if a value exists in a JSON array.
Examples
SELECT json_array_contains(json_extract(json_parse('{"ticket_id": 5521, "tags": ["billing", "refund", "urgent"]}'), '$.tags'), 'urgent') AS is_urgent;
| is_urgent |
| --------- |
| true      |
SELECT json_array_contains(json_parse('[12, 47, 305]'), '47') AS string_matches_number;
| string_matches_number |
| --------------------- |
| false                 |
Returns the number of elements in a JSON array.
Parameters
json:
extension<arrow.json>
The input JSON value or JSON string.
Examples
SELECT json_array_length(json_extract('{"order_id":"ord_918","items":[{"sku":"A1","qty":2},{"sku":"B2","qty":1},{"sku":"C3","qty":4}]}', '$.items')) AS line_item_count;
| line_item_count |
| --------------- |
| 3               |
SELECT coalesce(json_array_length(json_extract('{"user_id":42}', '$.prior_chargebacks')), 0) AS prior_chargeback_count;
| prior_chargeback_count |
| ---------------------- |
| 0                      |
Extracts a value from JSON or a JSON string using a path expression.
Examples
SELECT json_extract('{"order_id": "A-1042", "items": [{"sku": "MUG-01", "qty": 2}, {"sku": "TEE-XL", "qty": 1}]}', '$.items[*].sku') AS skus;
| skus                |
| ------------------- |
| ["MUG-01","TEE-XL"] |
SELECT CAST(json_extract('{"device": {"os": "iOS", "risk_score": 0.82}}', '$.device.risk_score') AS DOUBLE) > 0.7 AS high_risk_device;
| high_risk_device |
| ---------------- |
| true             |
Extracts an array from JSON string using a path expression.
Examples
SELECT cardinality(json_extract_array('{"txn_id":"t-77","risk_flags":["new_device","vpn","velocity"]}', '$.risk_flags')) AS risk_flag_count;
| risk_flag_count |
| --------------- |
| 3               |
SELECT json_extract_array('{"order_id":"o-981","items":[{"sku":"SKU-1042","qty":2},{"sku":"SKU-2210","qty":1},{"sku":"SKU-1042","qty":1}]}', '$.items[*].sku') AS skus;
| skus                                 |
| ------------------------------------ |
| ["SKU-1042", "SKU-2210", "SKU-1042"] |
Alias for json_extract.
Examples
SELECT json_extract_path('{"event":"charge.succeeded","data":{"amount":4999,"card":{"brand":"visa","last4":"4242","country":"US"}}}', '$.data.card') AS card_details;
| card_details                                   |
| ---------------------------------------------- |
| {"brand":"visa","country":"US","last4":"4242"} |
SELECT json_extract_path('{"order_id":"A-1001","items":[{"sku":"MUG-01","qty":2},{"sku":"TEE-M","qty":1}]}', '$.items[1].sku') AS second_item_sku;
| second_item_sku |
| --------------- |
| "TEE-M"         |
Examples
SELECT json_extract_path_text('{"merchant": {"name": "Blue Bottle Coffee", "mcc": "5814"}, "amount": 6.75}', '$.merchant.mcc') AS merchant_mcc;
| merchant_mcc |
| ------------ |
| 5814         |
SELECT json_extract_path_text('{"order_id": "ord_8812", "items": [{"sku": "A-100", "qty": 1}, {"sku": "B-200", "qty": 3}]}', '$.items[1].sku') AS second_item_sku;
| second_item_sku |
| --------------- |
| B-200           |
SELECT CAST(json_extract_path_text('{"merchant": {"name": "Blue Bottle Coffee"}, "amount": 1250.00}', '$.amount') AS DOUBLE) > 1000 AS is_large_txn;
| is_large_txn |
| ------------ |
| true         |
Extracts a scalar value from JSON or a JSON string using a JSONPath expression.
Examples
SELECT CAST(json_extract_scalar('{"event": "charge.succeeded", "data": {"amount": 4999, "currency": "usd", "card": {"country": "CA"}}}', '$.data.amount') AS DOUBLE) / 100 AS amount_dollars;
| amount_dollars |
| -------------- |
| 49.99          |
SELECT json_extract_scalar('{"order_id": "o-881", "items": [{"sku": "SKU-42", "qty": 2}, {"sku": "SKU-7", "qty": 1}]}', '$.items[0].sku') AS first_sku;
| first_sku |
| --------- |
| SKU-42    |
SELECT json_extract_scalar('{"items": [{"sku": "SKU-42"}]}', '$.items') IS NULL AS array_path_is_null;
| array_path_is_null |
| ------------------ |
| true               |
Examples
SELECT json_extract_string('{"event": "charge.failed", "data": {"card": {"brand": "visa", "decline_code": "insufficient_funds"}}}', '$.data.card.decline_code') AS decline_code;
| decline_code       |
| ------------------ |
| insufficient_funds |
SELECT json_extract_string('{"items": [{"sku": "SHOE-42", "qty": 1}, {"sku": "SOCK-07", "qty": 3}]}', '$.items[1].sku') AS second_sku;
| second_sku |
| ---------- |
| SOCK-07    |
SELECT coalesce(json_extract_string('{"device": {"os": "ios"}}', '$.device.browser'), 'unknown') AS browser;
| browser |
| ------- |
| unknown |
Encodes a JSON value into a string
Parameters
json:
extension<arrow.json>
The input JSON value or JSON string.
Examples
SELECT json_format(json_extract(json_parse('{"order_id": "A-1009", "shipping": {"country": "US", "zip": "94107"}}'), '$.shipping')) AS shipping_json;
| shipping_json                  |
| ------------------------------ |
| {"country":"US","zip":"94107"} |
SELECT json_format(json_parse('{ "merchant": "Blue Bottle",  "amount": 4.50, "currency": "USD" }')) AS canonical_payload;
| canonical_payload                                         |
| --------------------------------------------------------- |
| {"amount":4.50,"currency":"USD","merchant":"Blue Bottle"} |
SELECT json_format(cast_to_json(MAP(ARRAY['failed_logins_1h', 'distinct_ips_24h'], ARRAY[3, 2]))) AS risk_signals_json;
| risk_signals_json                           |
| ------------------------------------------- |
| {"distinct_ips_24h":2,"failed_logins_1h":3} |
Returns true when a JSON path resolves to a JSON null value.
Examples
SELECT transform(ARRAY['{"amount": 12.5, "merchant_id": null}', '{"amount": 40.0}', '{"amount": 9.99, "merchant_id": "m_881"}'], p -> json_is_null(p, '$.merchant_id')) AS merchant_explicitly_null;
| merchant_explicitly_null |
| ------------------------ |
| [true, false, false]     |
SELECT transform(ARRAY['{"kyc": {"ssn_last4": null}}', '{"kyc": {}}', '{"kyc": {"ssn_last4": "1234"}}'], p -> CASE WHEN json_is_null(p, '$.kyc.ssn_last4') THEN 'declined' WHEN json_extract_scalar(p, '$.kyc.ssn_last4') IS NULL THEN 'not_asked' ELSE 'provided' END) AS ssn_status;
| ssn_status                      |
| ------------------------------- |
| [declined, not_asked, provided] |
Converts an arbitrary value into a JSON string
Parameters
string:
large_string
The input string.
Examples
SELECT json_parse('{"user_id": 42,  "plan": "pro" , "seats": 5}') AS profile;
| profile                               |
| ------------------------------------- |
| {"plan":"pro","seats":5,"user_id":42} |
SELECT json_extract_scalar(json_parse('{"event": "login", "device": {"os": "ios", "version": "17.2"}}'), '$.device.os') AS device_os;
| device_os |
| --------- |
| ios       |
Returns the size of a JSON object or array at a path.
Examples
SELECT json_size('{"order_id": "A-1042", "items": [{"sku": "TEE-M"}, {"sku": "MUG-01"}, {"sku": "CAP-L"}]}', '$.items') AS line_item_count;
| line_item_count |
| --------------- |
| 3               |
SELECT json_size('{"device": {"os": "iOS", "model": "iPhone15", "locale": "en-US", "vpn": false}, "ip": "203.0.113.9"}', '$.device') AS device_attr_count;
| device_attr_count |
| ----------------- |
| 4                 |
Encodes a JSON value into a string. This is an alias for `json_format`.
Parameters
json:
extension<arrow.json>
The input JSON value or JSON string.
Examples
SELECT json_stringify(json_parse('{"merchant": "Blue Bottle", "amount": 4.5, "tags": ["coffee", "food"]}')) AS payload;
| payload                                                          |
| ---------------------------------------------------------------- |
| {"amount":4.5,"merchant":"Blue Bottle","tags":["coffee","food"]} |
SELECT json_stringify(json_extract(json_parse('{"user": {"id": 42, "tier": "gold"}, "event": "login"}'), '$.user')) AS user_json;
| user_json               |
| ----------------------- |
| {"id":42,"tier":"gold"} |
Examples
SELECT json_value('{"merchant": {"name": "Blue Bottle Coffee", "mcc": "5814"}, "amount": 6.75}', '$.merchant.mcc') AS merchant_mcc;
| merchant_mcc |
| ------------ |
| 5814         |
SELECT CAST(json_value('{"order_id": "A-1042", "items": [{"sku": "TSHIRT-M", "qty": 2, "unit_price": 18.50}, {"sku": "MUG-01", "qty": 1, "unit_price": 12.00}]}', '$.items[0].unit_price') AS DOUBLE) * 2 AS first_line_total;
| first_line_total |
| ---------------- |
| 37.0             |
Converts an arbitrary value into a JSON string

Type parameters. T means matching inputs and outputs use the same type.

Parameters
The input value. T means matching inputs and outputs use the same type.
Examples
SELECT jsonify({'txn_id': 'txn_8841', 'amount': 42.5, 'tags': ['grocery', 'card_present']}) AS txn_json;
| txn_json                                                              |
| --------------------------------------------------------------------- |
| {"amount":42.5,"tags":["grocery","card_present"],"txn_id":"txn_8841"} |
SELECT jsonify({'user_id': 1017, 'risk_score': 0.82, 'is_flagged': true, 'last_login': NULL, 'shipping': {'country': 'US', 'zip': '94107'}}) AS user_json;
| user_json                                                                                                        |
| ---------------------------------------------------------------------------------------------------------------- |
| {"is_flagged":true,"last_login":null,"risk_score":0.82,"shipping":{"country":"US","zip":"94107"},"user_id":1017} |
Dispatches a JSON value to the lazy callback matching its runtime JSON type.

Type parameters. R is the callback result type.

Returns true when the input is syntactically valid JSON according to orjson.loads.
Examples
SELECT transform(ARRAY['{"amount": 19.99}', '{"amount": 19.99', '{"amount": NaN}', ''], p -> orjson_json_is_valid(p)) AS payload_is_valid;
| payload_is_valid            |
| --------------------------- |
| [true, false, false, false] |
SELECT CASE WHEN orjson_json_is_valid('{"order_id": 1042, "risk_score": NaN}') THEN 'parse' ELSE 'quarantine' END AS webhook_route;
| webhook_route |
| ------------- |
| quarantine    |
Extracts an element from a Python JSON list using Python integer indexing, returning null for non-lists and out-of-range indices.
Examples
SELECT CAST(python_json_array_get('[12.5, 40.0, 7.25]', -1) AS DOUBLE) AS last_amount;
| last_amount |
| ----------- |
| 7.25        |
SELECT json_extract_scalar(python_json_array_get('[{"merchant": "Uber", "amount": 23.1}, {"merchant": "Steam", "amount": 59.99}]', -1), '$.merchant') AS latest_merchant;
| latest_merchant |
| --------------- |
| Steam           |
SELECT COALESCE(CAST(python_json_array_get('["card_present"]', -2) AS VARCHAR), 'no_prior_txn') AS prev_channel;
| prev_channel |
| ------------ |
| no_prior_txn |
Either:
  • Extracts a Python JSON boolean, returning null for non-booleans.
  • Extracts a Python JSON boolean after following object keys, returning null for non-booleans.
Examples
SELECT python_json_extract_bool('{"card": {"three_ds": {"authenticated": false}}, "risk_score": NaN}', 'card', 'three_ds', 'authenticated') AS three_ds_authenticated;
| three_ds_authenticated |
| ---------------------- |
| false                  |
SELECT transform(ARRAY['{"is_fraud": true}', '{"is_fraud": "true"}', '{"is_fraud": 1}', '{}'], j -> python_json_extract_bool(j, 'is_fraud')) AS is_fraud_flags;
| is_fraud_flags           |
| ------------------------ |
| [true, NULL, NULL, NULL] |
Either:
  • Extracts a Python JSON dict, returning null for non-dicts.
  • Extracts a Python JSON dict after following object keys, returning null for non-dicts.
Examples
SELECT python_json_extract_dict('{"device": {"fingerprint": {"os": "iOS", "jailbroken": false}}, "velocity": Infinity}', 'device', 'fingerprint') AS device_fingerprint;
| device_fingerprint                 |
| ---------------------------------- |
| {"os": "iOS", "jailbroken": false} |
SELECT python_json_extract_dict('{"order_id": 981, "shipping": "pending"}', 'shipping') IS NULL AS shipping_not_a_dict;
| shipping_not_a_dict |
| ------------------- |
| true                |
Either:
  • Extracts a Python JSON float candidate, returning null for non-numbers.
  • Extracts a Python JSON float candidate after following object keys, returning null for non-numbers.
Examples
SELECT python_json_extract_float('{"payment": {"amount": 129.99, "currency": "USD"}}', 'payment', 'amount') AS payment_amount;
| payment_amount |
| -------------- |
| 129.99         |
SELECT COALESCE(python_json_extract_float('{"risk": {"score": "high"}}', 'risk', 'score'), -1.0) AS risk_score;
| risk_score |
| ---------- |
| -1.0       |
SELECT python_json_extract_float('{"score": Infinity}', 'score') AS model_score;
| model_score |
| ----------- |
| inf         |
Either:
  • Extracts a Python JSON integer, returning null for non-integers.
  • Extracts a Python JSON integer after following object keys, returning null for non-integers.
Examples
SELECT python_json_extract_int('{"order": {"id": "A-17", "quantity": 3, "discount": 0.15}}', 'order', 'quantity') AS quantity;
| quantity |
| -------- |
| 3        |
SELECT ARRAY[python_json_extract_int('{"retries": 3}', 'retries'), python_json_extract_int('{"retries": "3"}', 'retries'), python_json_extract_int('{"retries": 3.0}', 'retries'), python_json_extract_int('{"retries": true}', 'retries')] AS int_or_null;
| int_or_null           |
| --------------------- |
| [3, NULL, NULL, NULL] |
Either:
  • Extracts a Python JSON list, returning null for non-lists.
  • Extracts a Python JSON list after following object keys, returning null for non-lists.
Examples
SELECT python_json_extract_list('{"order": {"items": ["sku-1", "sku-2", "sku-3"]}}', 'order', 'items') AS order_items;
| order_items                 |
| --------------------------- |
| ["sku-1", "sku-2", "sku-3"] |
SELECT coalesce(json_array_length(python_json_extract_list('{"customer": {"id": 42, "tags": "vip"}}', 'customer', 'tags')), 0) AS tag_count;
| tag_count |
| --------- |
| 0         |
Either:
  • Extracts a Python JSON string, returning null for non-strings.
  • Extracts a Python JSON string after following object keys, returning null for non-strings.
Examples
SELECT python_json_extract_string('{"payment": {"method": "card", "card": {"brand": "visa", "last4": "4242"}}, "amount": 1999}', 'payment', 'card', 'brand') AS card_brand;
| card_brand |
| ---------- |
| visa       |
SELECT coalesce(python_json_extract_string('{"shipping": {"country": "US", "zip": 94107}}', 'shipping', 'zip'), 'unknown') AS shipping_zip;
| shipping_zip |
| ------------ |
| unknown      |
Dispatches a JSON value to the lazy callback matching its runtime JSON type.

Type parameters. R is the callback result type.

Returns true when the input is syntactically valid JSON.
Examples
SELECT python_json_is_valid('{"event": "payment.succeeded", "amount_cents": 1999, "currency": "usd"') AS webhook_is_parseable;
| webhook_is_parseable |
| -------------------- |
| false                |
SELECT transform(ARRAY['{"score": 0.91}', '{"score": NaN}', '{score: 0.5}', '{"score": 0.7,}'], p -> python_json_is_valid(p)) AS payload_is_valid;
| payload_is_valid           |
| -------------------------- |
| [true, true, false, false] |
Extracts a nested field from a Python JSON object using string keys, returning null for non-objects and missing keys.
Examples
SELECT python_json_object_get('{"billing": {"address": {"country": "DE"}}}', 'billing', 'address', 'country') AS billing_country;
| billing_country |
| --------------- |
| "DE"            |
SELECT coalesce(CAST(python_json_object_get('{"user_id": "u_42", "profile": {"loyalty": ["gold"]}}', 'profile', 'loyalty', 'tier') AS VARCHAR), 'standard') AS loyalty_tier;
| loyalty_tier |
| ------------ |
| standard     |
Returns the top-level size of a Python JSON object or array, or 0 for scalar values.
Examples
SELECT python_json_size(json_extract(json_parse('{"order_id": 88, "line_items": [{"sku": "A"}, {"sku": "B"}, {"sku": "C"}]}'), '$.line_items')) AS line_item_count;
| line_item_count |
| --------------- |
| 3               |
SELECT python_json_size(json_parse('{"device": {"os": "ios", "version": "17.4", "model": "iPhone15"}, "ip": "203.0.113.7", "tags": ["vip", "mobile"]}')) AS metadata_key_count;
| metadata_key_count |
| ------------------ |
| 3                  |
SELECT python_json_size(json_extract(json_parse('{"order_id": 88, "line_items": [{"sku": "A"}]}'), '$.order_id')) AS scalar_size;
| scalar_size |
| ----------- |
| 0           |
Parses a Python JSON value, returning null for invalid JSON.
Examples
SELECT python_json_object_get(python_json_value('{"merchant": "Blue Bottle", "fraud_score": NaN}'), 'merchant') AS merchant;
| merchant      |
| ------------- |
| "Blue Bottle" |
SELECT transform(ARRAY['{"amount": 42.0, "risk": NaN}', '{"amount": 12.5,}', 'None'], m -> python_json_value(m) IS NOT NULL) AS is_valid_payload;
| is_valid_payload     |
| -------------------- |
| [true, false, false] |
Evaluate a Rego query against a policy via the regorus interpreter. Arguments are (policy, query, input_json, data_json); the result is the regorus QueryResults serialized as a JSON string.
Examples
SELECT json_extract_scalar(regorus_eval('package txn
default allow := false
allow if { input.amount < 1000; input.country == "US" }', 'data.txn.allow', '{"amount": 250, "country": "US"}', ''), '$.result[0].expressions[0].value') AS allow;
| allow |
| ----- |
| true  |
SELECT json_extract(regorus_eval('package risk
reasons contains "amount_over_limit" if input.amount > data.limits.max_amount
reasons contains "blocked_country" if input.country in data.limits.blocked_countries
reasons contains "new_account" if input.account_age_days < 30', 'data.risk.reasons', '{"amount": 4200, "country": "KP", "account_age_days": 400}', '{"limits": {"max_amount": 2500, "blocked_countries": ["KP", "IR"]}}'), '$.result[0].expressions[0].value') AS flag_reasons;
| flag_reasons                            |
| --------------------------------------- |
| ["amount_over_limit","blocked_country"] |
Examples
SELECT '{"family": "anatidae"}' ->> '$.family';
Decodes a Base64url-encoded string to binary data.
Parameters
string:
large_string
The input string.
Encodes binary data to a Base64url string.
Parameters
binary:
large_binary
The input binary value.
Decodes URL-encoded characters in a string.
Parameters
value:
large_string
The input value.
URL-encodes special characters in a string.
Parameters
value:
large_string
The input value.
Extracts the fragment portion (after #) from a URL.
Parameters
url:
large_string
The URL to request.
Returns the host from a URL.
Parameters
url:
large_string
The URL to request.
Extracts the value of a specific query parameter from a URL.
Parameters
url:
large_string
The URL to request.
name:
large_string
Returns the path from a URL.
Parameters
url:
large_string
The URL to request.
Extracts the port number from a URL.
Parameters
url:
large_string
The URL to request.
Returns the protocol from a URL.
Parameters
url:
large_string
The URL to request.
Extracts the query string portion (after ?) from a URL.
Parameters
url:
large_string
The URL to request.
Downloads a file from object storage (gs://, s3://, abfs://) and returns the raw bytes. Returns null on error.
Parameters
uri:
large_string
Downloads a file from object storage (gs://, s3://, abfs://) and returns a struct with data, success, error, and metadata.
Parameters
uri:
large_string
Computes an Amazon Titan text embedding for the input string via AWS Bedrock and returns the embedding as a float vector.
Parameters
text:
large_string
The input text.
model_id:
large_string
The model identifier to invoke.
dimensions:
int64
= NULL
The embedding dimension count.
normalize:
bool
= NULL
aws_access_key_id_override:
large_string
= NULL
aws_session_token_override:
large_string
= NULL
aws_role_arn_override:
large_string
= NULL
aws_region_override:
large_string
= NULL
aws_profile_name_override:
large_string
= NULL
Invokes an AWS Bedrock model via InvokeModel with the provided binary request body and returns the raw binary response body.
Parameters
body:
large_binary
The request body.
model_id:
large_string
The model identifier to invoke.
content_type:
large_string
= NULL
The request content type.
accept:
large_string
= NULL
The response MIME type to request.
aws_access_key_id_override:
large_string
= NULL
aws_session_token_override:
large_string
= NULL
aws_role_arn_override:
large_string
= NULL
aws_region_override:
large_string
= NULL
aws_profile_name_override:
large_string
= NULL
Alias of `prompt_jev`: asks Jev's structured-decision API a set of typed questions (noul/choice/score) about `state` and returns the answers as a JSON string alongside usage statistics.
Parameters
state:
large_string
The current state value.
questions:
large_string
model:
large_string
= NULL
api_server:
large_string
= NULL
api_key:
large_string
= NULL
Makes a completion request to OpenAI's chat API and returns the response.
Parameters
prompt:
large_string
model:
large_string
= NULL
api_server:
large_string
= NULL
api_key:
large_string
= NULL
max_tokens:
int64
= NULL
temperature:
double
= NULL
service_tier:
large_string
= NULL
response_format:
large_string
= NULL
chat_template_kwargs:
large_string
= NULL
Examples
SELECT openai_complete('Classify this card transaction memo into exactly one category from [groceries, dining, travel, utilities, other]. Reply with the category only, lowercase. Memo: UBER *TRIP SAN FRANCISCO CA', model => 'gpt-4o-mini', temperature => 0.0, max_tokens => 5).completion AS memo_category;
| memo_category |
| ------------- |
| travel        |
SELECT openai_complete('Rate the urgency of this support ticket from 1 (low) to 5 (critical) and name its topic in one word. Ticket: Our checkout page has returned 500 errors for every customer since 9am.', model => 'gpt-4o-mini', temperature => 0.0, response_format => '{"type": "json_schema", "json_schema": {"name": "ticket", "strict": true, "schema": {"type": "object", "properties": {"urgency": {"type": "integer"}, "topic": {"type": "string"}}, "required": ["urgency", "topic"], "additionalProperties": false}}}').completion AS ticket_triage;
| ticket_triage                    |
| -------------------------------- |
| {"topic":"Checkout","urgency":5} |
Makes a completion request to OpenAI's chat API and returns the raw JSON response string.
Parameters
prompt:
large_string
model:
large_string
= NULL
api_server:
large_string
= NULL
api_key:
large_string
= NULL
max_tokens:
int64
= NULL
temperature:
double
= NULL
service_tier:
large_string
= NULL
response_format:
large_string
= NULL
chat_template_kwargs:
large_string
= NULL
Examples
SELECT json_extract_scalar(openai_complete_raw('Classify this card transaction memo into one category (groceries, travel, dining, utilities). Reply with only the category: UBER *TRIP SAN FRANCISCO', model => 'gpt-4o-mini', temperature => 0.0), '$.choices[0].message.content') AS memo_category;
| memo_category |
| ------------- |
| travel        |
SELECT json_extract_scalar(openai_complete_raw('Summarize this support ticket in one sentence: My order #4821 arrived with a cracked screen and I need a replacement before Friday.', model => 'gpt-4o-mini', max_tokens => 5, temperature => 0.0), '$.choices[0].finish_reason') AS finish_reason;
| finish_reason |
| ------------- |
| length        |
Makes an embedding request to OpenAI's embeddings API and returns the response.
Parameters
input:
large_string
The input value.
model:
large_string
= NULL
api_server:
large_string
= NULL
api_key:
large_string
= NULL
dimensions:
int64
= NULL
The embedding dimension count.
Examples
SELECT round(cosine_similarity_vector(openai_embed('Wireless noise-cancelling headphones', model => 'text-embedding-3-small').embedding, openai_embed('Bluetooth over-ear headset with ANC', model => 'text-embedding-3-small').embedding), 1) AS title_similarity;
| title_similarity |
| ---------------- |
| 0.6              |
SELECT cardinality(openai_embed('Wireless noise-cancelling headphones', model => 'text-embedding-3-small', dimensions => 256).embedding) AS embedding_dims;
| embedding_dims |
| -------------- |
| 256            |
Asks Jev's structured-decision API a set of typed questions (noul/choice/score) about `state` and returns the answers as a JSON string alongside usage statistics.
Parameters
state:
large_string
The current state value.
questions:
large_string
model:
large_string
= NULL
api_server:
large_string
= NULL
api_key:
large_string
= NULL
Invokes an AWS SageMaker endpoint for inference with the provided binary input and returns the binary output.
Parameters
body:
large_binary
The request body.
endpoint:
large_string
The name of the model endpoint to invoke.
content_type:
large_string
The request content type.
target_model:
large_string
target_variant:
large_string
Invokes a Vertex AI endpoint for inference with binary input, returns binary output.
Parameters
body:
large_binary
The request body.
endpoint:
large_string
The name of the model endpoint to invoke.
content_type:
large_string
= NULL
The request content type.
gcp_credentials_override:
large_string
= NULL
dedicated_endpoint_dns:
large_string
= NULL
method:
large_string
= NULL
The HTTP method, such as 'GET' or 'POST'.
api_host:
large_string
= NULL
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geojson:
large_string
The geometry as a GeoJSON string.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
distance:
double
The buffer distance.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
wkt:
large_string
The geometry in WKT format.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
index:
int32
The index to read.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
index:
int32
The index to read.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
wkt:
large_string
The geometry in WKT format.
Geospatial (Presto-flavored Velox geometry function).
Parameters
points:
large_list<item: large_binary>
The array of point geometries.
Geospatial (Presto-flavored Velox geometry function).
Parameters
points:
large_list<item: large_binary>
The array of point geometries.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
x:
double
The input value.
y:
double
The second input value.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
index:
int32
The index to read.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
wkt:
large_string
The geometry in WKT format.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
relation:
large_string
The DE-9IM intersection matrix pattern.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry1:
large_binary
The first input geometry, as WKB.
geometry2:
large_binary
The second input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Geospatial (Presto-flavored Velox geometry function).
Parameters
geometry:
large_binary
The input geometry, as WKB.
Calculates the lat-lon in degrees for a given h3 cell.
Parameters
cell:
large_string
The H3 cell identifier.
Calculates the lat-lon for a given h3 cell.
Parameters
cell:
large_string
The H3 cell identifier.
Converts Avro binary data to a structured format using an Avro schema.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
schema:
large_string
The schema definition.
A (possibly null) struct value whose type defines the result shape. T means matching inputs and outputs use the same type.
binary:
large_binary
The input binary value.
Decodes a Base64-encoded string to binary data.
Parameters
string:
large_string
The input string.
Convert a 32-bit big-endian bytes value to an integer.
Convert a 64-bit big-endian bytes value to an integer.
Converts a hexadecimal string to binary data.
Parameters
string:
large_string
The input string.
Decodes the 32-bit big-endian binary representation of an IEEE 754 floating-point value.
Parameters
binary:
large_binary
The input binary value.
Decodes the 64-bit big-endian binary representation of an IEEE 754 floating-point value.
Parameters
binary:
large_binary
The input binary value.
Decompress snappy-compressed binary data.
gunzip the input binary data.
Converts protobuf binary data to a structured format.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
descriptor:
large_binary
The serialized protobuf FileDescriptorSet.
message_name:
large_string
The fully-qualified protobuf message name.
A (possibly null) struct value whose type defines the result shape. T means matching inputs and outputs use the same type.
binary:
large_binary
The input binary value.
Converts protobuf binary data to a structured format, recording parse errors with row attribution.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
descriptor:
large_binary
The serialized protobuf FileDescriptorSet.
message_name:
large_string
The fully-qualified protobuf message name.
A (possibly null) struct value whose type defines the result shape. T means matching inputs and outputs use the same type.
binary:
large_binary
The input binary value.
Decodes UTF-8 encoded binary data using Python's strict bytes.decode() semantics.
Parameters
binary:
large_binary
The input binary value.
Converts structured data to protobuf binary format.

Type parameters. T means matching inputs and outputs use the same type.

Parameters
descriptor:
large_binary
The serialized protobuf FileDescriptorSet.
message_name:
large_string
The fully-qualified protobuf message name.
The input value. T means matching inputs and outputs use the same type.
Encodes binary data to a Base64 string.
Parameters
binary:
large_binary
The input binary value.
Encodes an integer into a 32-bit big-endian binary representation.
Parameters
integer:
int32
Encodes a bigint into a 64-bit big-endian binary representation.
Parameters
bigint:
int64
Converts binary data to its hexadecimal string representation.
Parameters
binary:
large_binary
The input binary value.
Encodes a float as a 32-bit big-endian binary in IEEE 754 format.
Parameters
real:
float
Encodes a double as a 64-bit big-endian binary in IEEE 754 format.
Parameters
double:
double
Snappy-compress binary data.
Calculates the CRC32 checksum of binary data.
Parameters
binary:
large_binary
The input binary value.
Computes HMAC-MD5 authentication code for data using a secret key.
Parameters
binary:
large_binary
The input binary value.
key:
large_binary
The map key to read or update.
Computes HMAC-SHA1 authentication code for data using a secret key.
Parameters
binary:
large_binary
The input binary value.
key:
large_binary
The map key to read or update.
Computes HMAC-SHA256 authentication code for data using a secret key.
Parameters
binary:
large_binary
The input binary value.
key:
large_binary
The map key to read or update.
Computes HMAC-SHA512 authentication code for data using a secret key.
Parameters
binary:
large_binary
The input binary value.
key:
large_binary
The map key to read or update.
Returns the Iceberg bucket id for a value: (murmur3_x86_32(value) & 2147483647) % num_buckets.
Examples
SELECT iceberg_bucket(34, 100);
SELECT iceberg_bucket('iceberg', 100);
Computes the MD5 hash of binary data.
Parameters
binary:
large_binary
The input binary value.
Computes the SHA-1 hash of binary data.
Parameters
binary:
large_binary
The input binary value.
Computes the SHA-256 hash of binary data.
Parameters
binary:
large_binary
The input binary value.
Computes the SHA-512 hash of binary data.
Parameters
binary:
large_binary
The input binary value.
Computes a 32-bit SpookyHash V2 hash of binary data.
Parameters
binary:
large_binary
The input binary value.
Computes a 64-bit SpookyHash V2 hash of binary data.
Parameters
binary:
large_binary
The input binary value.
Computes a 64-bit XXHash of binary data, optionally with a seed.
Converts a string representation of a number in a given base to an integer.
Parameters
string:
large_string
The input string.
radix:
int64
The base (radix) to convert to.
Decodes UTF-8 encoded binary data, optionally replacing invalid sequences.
Converts an integer to its string representation in the specified base.
Parameters
value:
int64
The integer to convert.
radix:
int64
The base (radix) to convert to.
Encodes a string to UTF-8 binary data.
Parameters
string:
large_string
The input string.
Runs a SQL query directly against a registered datasource and returns the datasource result as a table. Use this when the SQL should be interpreted by the datasource dialect instead of the Chalk SQL dialect.
Parameters
The name of the registered datasource to query.
query:
string
The SQL query to execute against the datasource.
Examples
SELECT * FROM datasource_query('my_postgres', 'SELECT id, email FROM public.users LIMIT 10');