Functions for structures
ExpandStruct
Adding one or more new fields to the structure.
If the field set contains duplicate values, an error is returned.
Arguments:
- The first argument passes the source structure to be expanded.
- All the other arguments must be named, each argument adds a new field and the argument's name is used as the field's name (as in AsStruct).
Examples
$struct = AsStruct(1 AS a);
SELECT
ExpandStruct(
$struct,
2 AS b,
"3" AS c
) AS abc;
AddMember
Adding one new field to the structure. If you need to add multiple fields, better use ExpandStruct.
If the field set contains duplicate values, an error is returned.
Arguments:
- Source structure.
- Name of the new field.
- Value of the new field.
Examples
$struct = AsStruct(1 AS a);
SELECT
AddMember(
$struct,
"b",
2
) AS ab;
RemoveMember
Removing a field from the structure.
If the entered field hasn't existed, an error is returned.
Arguments:
- Source structure.
- Field name.
Examples
$struct = AsStruct(1 AS a, 2 AS b);
SELECT
RemoveMember(
$struct,
"b"
) AS a;
ForceRemoveMember
Removing a field from the structure.
If the entered field hasn't existed, unlike RemoveMember, the error is not returned.
Arguments:
- Source structure.
- Field name.
Examples
$struct = AsStruct(1 AS a, 2 AS b);
SELECT
ForceRemoveMember(
$struct,
"c"
) AS ab;
CombineMembers
Combining the fields from multiple new structures into another new structure.
If the resulting field set contains duplicate values, an error is returned.
Arguments:
- Two or more structures.
Examples
$struct1 = AsStruct(1 AS a, 2 AS b);
$struct2 = AsStruct(3 AS c);
SELECT
CombineMembers(
$struct1,
$struct2
) AS abc;
FlattenMembers
Combining the fields from multiple new structures into another new structure with prefix support.
If the resulting field set contains duplicate values, an error is returned.
Arguments:
- Two or more tuples of two elements: prefix and structure.
Examples
$struct1 = AsStruct(1 AS a, 2 AS b);
$struct2 = AsStruct(3 AS c);
SELECT
FlattenMembers(
AsTuple("foo", $struct1), -- fooa, foob
AsTuple("bar", $struct2) -- barc
) AS abc;