OBJECT_CONSTRUCT
functionsupportedCore SQL functionsReturns an OBJECT constructed from the arguments.
Syntax
supportedpartialnot supportednot scored
OBJECT_CONSTRUCT( [<key>, <value> [, <key>, <value> , ...]] )
OBJECT_CONSTRUCT(*)
Parameters
| Name | Required | Description |
|---|---|---|
key | required | The key in a key-value pair. Each key is a VARCHAR value. |
value | required | The value that is associated with the key. The value can be any data type. |
* | required | When invoked with an asterisk (wildcard), the OBJECT value is constructed from the specified data using the attribute names as keys and the associated values as values. See the examples below. When you pass a wildcard to the function, you can qualify the wildcard with the name or alias for the table. For example, to pass in all of the columns from the table named mytable, specify the following: Copy code (mytable.*) You can also use the ILIKE and EXCLUDE keywords for filtering: ILIKE filters for column names that match the specified pattern. Only one pattern is allowed. For example: Copy code (* ILIKE 'col1%') EXCLUDE filters out column names that don’t match the specified column or columns. For example: Copy code (* EXCLUDE col1) (* EXCLUDE (col1, col2)) Qualifiers are valid when you use these keywords. The following example uses the ILIKE keyword to filter for all of the columns that match the pattern col1% in the table mytable: Copy code (mytable.* ILIKE 'col1%') The ILIKE and EXCLUDE keywords can’t be combined in a single function call. You can also specify the wildcard in an object constant. For this function, the ILIKE and EXCLUDE keywords are valid only in a SELECT list or GROUP BY clause. For more information about the ILIKE and EXCLUDE keywords, see the “Parameters” section in SELECT. |
Returns
Returns a value of type OBJECT.
Usage notes
- If the key or value is NULL — that is, SQL NULL — the key-value pair is omitted from the resulting object. A key-value pair consisting of a string that isn’t NULL as the key and a JSON null as the value — that is, PARSE_JSON('NULL') — isn’t omitted. For more information, see NULL values.
- The constructed object does not necessarily preserve the original order of the key-value pairs.
- In many contexts, you can use an OBJECT constant (also called an OBJECT literal) instead of the OBJECT_CONSTRUCT function.