21.3. Union Type Functions #
-
union_extract(union_col, tag) returns#duckdb.unresolved_type Extracts a value from a union type by specifying the tag name of the member to access.
Example 21.5.
-- Extract the string value if the union contains a string SELECT union_extract(my_union_column, 'string') FROM my_table; -- Extract integer value from union SELECT union_extract(data_field, 'integer') AS extracted_int FROM mixed_data;
Required parameters:
Name
Type
Description
union_colduckdb.union or duckdb.unresolved_typeThe union column from which to extract a value
tagtextThe tag name of the union member to extract
-
union_tag(union_col) returns#duckdb.unresolved_type Returns the tag name of the currently active member in a union type.
Example 21.6.
-- Get the active tag for each row SELECT union_tag(my_union_column) AS active_type FROM my_table; -- Filter rows based on union tag SELECT * FROM my_table WHERE union_tag(data_field) = 'string';
Required parameters:
Name
Type
Description
union_colduckdb.union or duckdb.unresolved_typeThe union column from which to get the tag