- Categories:
Semi-structured and structured data functions (Array/Object)
OBJECT_DELETE¶
Returns an object containing the contents of the input (that is, source) object with one or more keys removed.
Syntax¶
Arguments¶
objectThe source object.
key1,key2Keys to be omitted from the returned object.
Returns¶
This function returns a value of type OBJECT.
Usage notes¶
For structured OBJECTs:
For the arguments that are keys, you must specify constants.
If the specified key isn’t part of the OBJECT type definition, the call fails. For example, the following call fails because the OBJECT value doesn’t contain the specified key
zip_code:The function returns a structured OBJECT value. The type of the OBJECT value excludes the deleted key. For example, suppose that you remove the
citykey:The function returns an OBJECT value of the type
OBJECT(state VARCHAR), which doesn’t include thecitykey.If the function removes all keys from the OBJECT value, the function returns an empty structured OBJECT value of the type
OBJECT().When the type of a structured OBJECT value includes key-value pairs, the names and types of those pairs are included in parentheses in the type (for example, OBJECT(city VARCHAR)). Because an empty structured OBJECT value contains no key-value pairs, the parentheses are empty.
Examples¶
This query returns an object that excludes the keys a and b from the source object:
Create a table and insert rows with OBJECT values. This example uses OBJECT constants in the INSERT statements.
Query the table to see the data:
To delete the employee_date_of_birth key from the query output, execute the following query:
To query the employee_contact nested object, remove the phone key from it, and
return only the nested inner key-value pairs, execute the following query:
To query the employee_contact nested object, remove the phone key from it, and
return the full object instead of just the nested inner key-value pairs, run a query
that performs the following actions:
Call the OBJECT_INSERT function and specify the
ovcolumn for the first argument. The function starts with the whole object in each row.For the second argument in the OBJECT_INSERT call, specify
employee_contactfor the existing key to update.For the third argument in the OBJECT_INSERT call, call the OBJECT_DELETE function to remove the
phonekey from the nested object.For the last argument in the OBJECT_INSERT call, specify
trueto replace the old object with the new one.
Execute the following query to perform these actions: