MAP_CONSTRUCT
functionsupportedCore SQL functionsReturns a MAP constructed from a series of alternating keys and values.
Syntax
supportedpartialnot supportednot scored
MAP_CONSTRUCT( <key_1>, <value_1> [ , <key_2>, <value_2> , ... ] )
Parameters
| Name | Required | Description |
|---|---|---|
key_N | required | The key in a key-value pair. A key must be a VARCHAR or numeric value. All of the keys are cast to a single, common key type. |
value_N | required | The value that is associated with the key. All of the values are cast to a single, common value type. |
Returns
Returns a MAP whose key type is the common type of the keys (VARCHAR or a numeric type) and whose value type is the common type of the values. For example, MAP_CONSTRUCT('a', 1, 'b', 2) returns a MAP(VARCHAR, NUMBER) value.
Usage notes
- You must specify an even number of arguments (one or more key-value pairs). Specifying an odd number of arguments returns an error.
- A key must be a VARCHAR or numeric value. Other key types (for example, BOOLEAN or DATE) aren’t supported and return an error.
- All of the keys are cast to a single, common key type, and all of the values are cast to a single, common value type. For example, in MAP_CONSTRUCT(1, 'a', '2', 'b') the keys are unified to a numeric type.
- The keys in a map must be unique. If two keys are equal, the function returns an error.
- If a key is NULL, the key-value pair is omitted from the resulting map.
- If a value is NULL, the key-value pair is kept.
- The entries in the resulting map are ordered by key.
- To construct a semi-structured OBJECT instead of a MAP, use OBJECT_CONSTRUCT or OBJECT_CONSTRUCT_KEEP_NULL.