NAMED_STRUCT
Description
The named_struct
function is used to create a struct with specified field names and corresponding field values. This function can combine multiple fields and their values into a whole, making it convenient to display data in a structured form in query results.
Syntax Format
Parameter Description
f1, f2, ..., fN
: Field names, type is string, representing the names of each field in the struct.v1, v2, ..., vN
: Field values, types areT1, T2, ..., TN
, representing the values corresponding to each field in the struct.
Return Type
- Returns a struct containing fields such as
f1:T1, f2:T2, ..., fN:TN
.
Usage Example
Example 1: Creating a simple named struct
Return Results:
Example 2: Creating Complex Structures with Other Functions
Return Results:
Example 3: Using Named Structs in Queries
Assume the users
table contains the fields id
, name
, and age
, and the return result is:
Notes
- Please ensure that the values of the field names
f1, f2, ..., fN
are valid strings, otherwise it may cause the function to fail. - When field names conflict with existing field names, you need to use aliases or other methods to avoid conflicts.
- When using the
named_struct
function, please pay attention to the matching of field value types with the field types in the structure to ensure data correctness.