Skip to main content

Struct Functions

NameDescription
struct.entryDot notation that serves as an alias for struct_extract from named STRUCTs.
struct[entry]Bracket notation that serves as an alias for struct_extract from named STRUCTs.
struct[idx]Bracket notation that serves as an alias for struct_extract from unnamed STRUCTs (tuples), using an index (1-based).
row(any, ...)Create an unnamed STRUCT (tuple) containing the argument values.
struct_concat(structs...)Merge the multiple structs into a single STRUCT.
struct_contains(struct, entry)Check if the STRUCT contains the specified entry.
struct_extract(struct, 'entry')Extract the named entry from the STRUCT.
struct_extract(struct, idx)Extract the entry from an unnamed STRUCT (tuple) using an index (1-based).
struct_extract_at(struct, idx)Extract the entry from a STRUCT (tuple) using an index (1-based).
struct_insert(struct, name := any, ...)Add field(s) to an existing STRUCT.
struct_pack(name := any, ...)Create a STRUCT containing the argument values. The entry name will be the bound variable name.
struct_position(struct, entry)Return the index of the entry within the STRUCT (1-based), or NULL if not found.
struct_update(struct, name := any, ...)Add or update field(s) of an existing STRUCT.
struct_values(struct)Return the values of a STRUCT as an unnamed STRUCT (tuple).

struct.entry

Dot notation that serves as an alias for struct_extract from named STRUCTs.

Query
SELECT ({'i': 3, 's': 'string'}).i AS i;
Result
 i--- 3

struct[entry]

Bracket notation that serves as an alias for struct_extract from named STRUCTs.

Query
SELECT ({'i': 3, 's': 'string'})['i'] AS i;
Result
 i--- 3

struct[idx]

Bracket notation that serves as an alias for struct_extract from unnamed STRUCTs (tuples), using an index (1-based).

Query
SELECT (row(42, 84))[1] AS first;
Result
 first-------    42

row(any, ...)

Create an unnamed STRUCT (tuple) containing the argument values.

Query
SELECT row(i, i % 4, i / 4) AS r FROM (SELECT 10 AS i);
Result
 r---------- (10,2,2)

struct_concat(structs...)

Merge the multiple structs into a single STRUCT.

Query
SELECT struct_concat(struct_pack(i := 4), struct_pack(s := 'string')) AS s;
Result
 s------------ (4,string)

struct_contains(struct, entry)

Check if the STRUCT contains the specified entry. Alias: struct_has.

Query
SELECT struct_contains(row(1, 2, 3), 2) AS contains;
Result
 contains---------- t

struct_extract(struct, 'entry')

Extract the named entry from the STRUCT.

Query
SELECT struct_extract({'i': 3, 'v2': 3, 'v3': 0}, 'i') AS i;
Result
 i--- 3

struct_extract(struct, idx)

Extract the entry from an unnamed STRUCT (tuple) using an index (1-based).

Query
SELECT struct_extract(row(42, 84), 1) AS first;
Result
 first-------    42

struct_extract_at(struct, idx)

Extract the entry from a STRUCT (tuple) using an index (1-based).

Query
SELECT struct_extract_at({'v1': 10, 'v2': 20, 'v3': 3}, 2) AS v;
Result
 v---- 20

struct_insert(struct, name := any, ...)

Add field(s) to an existing STRUCT.

Query
SELECT struct_insert({'a': 1}, b := 2) AS s;
Result
 s------- (1,2)

struct_pack(name := any, ...)

Create a STRUCT containing the argument values. The entry name will be the bound variable name.

Query
SELECT struct_pack(i := 4, s := 'string') AS s;
Result
 s------------ (4,string)

struct_position(struct, entry)

Return the index of the entry within the STRUCT (1-based), or NULL if not found. Alias: struct_indexof.

Query
SELECT struct_position(row(1, 2, 3), 2) AS pos;
Result
 pos-----   2

struct_update(struct, name := any, ...)

Add or update field(s) of an existing STRUCT.

Query
SELECT struct_update({'a': 1, 'b': 2}, b := 3, c := 4) AS s;
Result
 s--------- (1,3,4)

struct_values(struct)

Return the values of a STRUCT as an unnamed STRUCT (tuple).

Query
SELECT struct_values({'a': 1, 'b': 2, 'c': 3}) AS vals;
Result
 vals--------- (1,2,3)

This page contains: