user_properties column on users and the properties column on events, plus ClickHouse Map values extracted from them.
->> (get text)
Extracts a value from a JSON object by key (or from a JSON array by index) and returns it as text, which is what you usually want for filtering or display. Syntaxjson— the JSON value to read from.key— the object key (text) or array index (integer) to extract.
- The extracted value as text, or
NULLif the key or index is absent. Text.
Users on the pro plan
-> (get JSON)
Extracts a value from a JSON object by key (or from a JSON array by index), returning it as a JSON value so it can be chained for nested lookups. Syntaxjson— the JSON value to read from.key— the object key (text) or array index (integer) to extract.
- The extracted value as JSON, or
NULLif the key or index is absent. JSON.
Country from a nested address object
@> (contains)
Tests whether the left JSON value contains the right JSON value — every key/value pair (or array element) on the right must be present on the left. Syntaxjson— the JSON value to search within.subset— a JSON value that must be contained; supply it as a JSON-formatted string literal.
trueifjsoncontainssubset, otherwisefalse. Boolean.
Users whose properties include plan pro
An explicit
::jsonb cast on either side — user_properties::jsonb @> '{"plan": "pro"}'::jsonb — behaves identically; the redundant cast is stripped.= ANY (JSON array)
Tests whether a scalar value equals any element of a JSON array. It is the common way to check membership in a JSON array stored on a property. Syntaxvalue— the scalar to look for.json_array— a JSON array value, such asuser_properties -> 'tags'.
trueifvaluematches at least one element, otherwisefalse. Boolean.
Users tagged vip
@? (path exists)
Tests whether a JSON path exists within a JSON value. Syntaxjson— the JSON value to test.path— a JSON path string, such as'$.plan'.
trueif the path matches something injson, otherwisefalse. Boolean.
Users who have a plan property set
jsonExtractInt
Extracts the value at a key from a JSON value as a signed integer. Syntaxjson— the JSON value to read from.key— the object key to extract.
- The value as a signed integer;
0if the key is absent or not numeric. Integer.
Users with a negative account balance
jsonExtractFloat
Extracts the value at a key from a JSON value as a floating-point number. Syntaxjson— the JSON value to read from.key— the object key to extract.
- The value as a float;
0if the key is absent or not numeric. Float.
Users with a lifetime value above 500
jsonExtractBool
Extracts the value at a key from a JSON value as a boolean. Syntaxjson— the JSON value to read from.key— the object key to extract.
- The value as a boolean;
falseif the key is absent or not a boolean. Boolean.
Users flagged as verified
jsonExtractUInt
Extracts the value at a key from a JSON value as an unsigned integer. Syntaxjson— the JSON value to read from.key— the object key to extract.
- The value as an unsigned integer;
0if the key is absent or not numeric. Unsigned integer.
Users with at least ten logins
is_json_valid
Tests whether a string is well-formed JSON. Syntaxtext— the string to validate.
trueif the string parses as valid JSON, otherwisefalse. Boolean.
Events with a well-formed properties payload
is_json_object
Tests whether a JSON value is an object (rather than an array, string, number, or scalar). Syntaxjson— the JSON value to inspect.
trueif the value is a JSON object, otherwisefalse. Boolean.
Rows where the address property is an object
json_path_exists
Tests whether a JSON path exists within a JSON value. It is the function form of the@? operator.
Syntax
json— the JSON value to test.path— a JSON path string, such as'$.address.country'.
trueif the path matches something injson, otherwisefalse. Boolean.
Users with a country in their address
json_has_any
Tests whether a JSON object contains any of the given top-level keys. Syntaxjson— the JSON object to inspect.keys— an array of key names to look for.
trueif at least one ofkeysis present as a top-level key, otherwisefalse. Boolean.
Users with a plan or tier property
jsonb_array_length
Returns the number of elements in a JSON array. Syntaxjson_array— the JSON array to measure.
- The element count. Integer.
Users with more than three tags
jsonb_object_keys
Expands the top-level keys of a JSON object into a set of rows, one key per row. Syntaxjson— the JSON object whose keys to list.
- A set of rows, each carrying one top-level key as text. Set of text values.
One row per property key per user
jsonb_array_elements_text
Expands a JSON array into a set of rows, one per element, with each element returned as text. Syntaxjson_array— the JSON array to expand.
- A set of rows, each carrying one array element as text. Set of text values.
One row per tag per user
jsonb_build_object
Builds a JSON object from alternating key and value arguments. Syntaxkey1, key2, ...— object keys (text).value1, value2, ...— the value paired with each preceding key.
- A JSON object built from the key/value pairs. JSON.
Repackage plan and country into an object
jsonb_build_array
Builds a JSON array from the given arguments, in order. Syntaxvalue1, value2, ...— the values to place into the array, in order.
- A JSON array containing the arguments. JSON.
A JSON array of a user's plan and country
::jsonb
Casts an expression to thejsonb type. It is most often used to give a string literal an explicit JSON type in a containment test.
Syntax
expression— the value to cast, typically a JSON-formatted string literal or a JSON column.
- The value as
jsonb. JSON.
Cast a literal for a containment test
On ClickHouse the
::jsonb cast is a no-op on a String-JSON column and resolves to the same path as a bare ->>.mapContains
Tests whether a map contains a given key. Syntaxmap— the map to inspect.key— the key to look for.
1if the map containskey, otherwise0.
Users whose metrics map tracks logins
mapKeys
Returns the keys of a map as an array (ClickHouse only). Syntaxmap— the map to read.
- An array of the map’s keys. Array.
The set of metric names per user
mapValues
Returns the values of a map as an array (ClickHouse only). Syntaxmap— the map to read.
- An array of the map’s values. Array.
All metric values per user
mapAdd
Merges two maps, summing the values of any keys they share. Keys present in only one map are carried through unchanged. Both maps must have numeric values (ClickHouse only). Syntaxmap1— the first map with numeric values.map2— the second map with numeric values.
- A map whose values are the per-key sums. Map.
Combine two quarterly usage maps
mapSubtract
Merges two maps, subtracting the second map’s values from the first for any keys they share. Both maps must have numeric values (ClickHouse only). Syntaxmap1— the map to subtract from.map2— the map of values to subtract.
- A map whose values are the per-key differences. Map.
Change in usage from Q1 to Q2
mapPopulateSeries
Fills the gaps in a map with integer keys, inserting missing consecutive keys with a zero value up to a given maximum. It is useful for turning a sparse counter map into a dense one (ClickHouse only). Syntaxmap— a map with integer keys and numeric values.max— optional highest key to fill up to; defaults to the map’s largest key.
- A map with every integer key from the smallest key up to
max, gaps filled with zero. Map.
Dense day-of-week login counts up to day 7
jsonb_strip_nulls
Returns a copy of a JSON value with every object field whose value is JSONnull removed. Null array elements are left untouched (PostgreSQL only).
Syntax
json— the JSON value to clean.
- The JSON value with null-valued object fields removed. JSON.
Drop null-valued properties