Categories:

Semi-structured Data Functions (Extraction)

GET

Extracts a value from an object or array; returns NULL if either of the arguments is NULL.

Note that this function should not be confused with the GET DML command.

See also:

GET_IGNORE_CASE , GET_PATH , :

Syntax

GET( <obj> , <field_name> )

GET( <v> , <field_name> )

GET( <array> , <index> )

GET( <v> , <index> )

Usage Notes

  • GET applies case-senstive matching to field names. For case-insenstive matching, try GET_IGNORE_CASE instead.

  • GET is a binary function that can be called in the following ways:

    • obj is an OBJECT value and field_name is a string value, which can be a constant or an expression.

      This variation of GET extracts VARIANT value of the field with the provided name from the object value. If the field is not found, NULL is returned. The field name should not be an empty string.

    • v is a VARIANT value and field_name is a string value, which can be a constant or an expression.

      Works similarly to GET with obj, but additionally checks that v contains an object value (and returns NULL if v does not contain an object).

    • array is an ARRAY value and index is an integer, which can be a constant or an expression.

      This variation of GET extracts VARIANT value of the array element with the given index. If the index points outside of the array boundaries, or if the indexed element does not exist (in sparse arrays) this function returns NULL.

    • v is a VARIANT value and index is an integer, which can be a constant or an expression.

      Works similarly to GET with array, but additionally checks that v contains an array value (and returns NULL if v does not contain an array).

Examples

Extract the maximum value of the field temperature from all objects in the vartab table which contain the field and the field sensorType equal to indoor:

SELECT MAX(AS_REAL(GET(v, 'temperature'))) FROM vartab WHERE AS_CHAR(GET(v, 'sensorType')) = 'indoor';

For more detailed examples, see Querying Semi-structured Data.