DB2 Table function - JSON_TABLE
The JSON_TABLE table function returns a result table from the evaluation of SQL/JSON path expressions. Each item in the result sequence of the row SQL/JSON path expression represents one or more rows in the result table.
The schema is SYSIBM. The function name cannot be specified as a qualified name.
If a character value is returned, it must contain correctly formatted JSON data (SQLSTATE 22032). If a binary data type is returned, it is interpreted according to the explicit or implicit FORMAT clause.
If JSON-expression is a character string data type, it is treated as JSON data.
If JSON-expression is a binary string data type, it is interpreted as UTF-8 data.
See CREATE TABLE statement for the description of built-in data types.
For more information about the content of an SQL/JSON path expression, see sql-json-path-expression.
Given an item from the result of processing the sql-json-path-expression as the externally provided context item, the column-path-expression-constant is evaluated and returns an output sequence. The column value is determined based on this output sequence as follows:
The value of column-path-expression-constant must not be an empty string or a string of all blanks. If the PATH clause is not specified, the column-path-expression-constant is defined as '$.' prefixed to column-name.
The column-path-expression-constant specifies an SQL/JSON path expression that determines the column value regarding the result of evaluating the SQL/JSON path expression in sql-json-path-expression.
The value for column-path-expression-constant must not be an empty string or a string of all blanks. If the PATH clause is not specified, the column-path-expression-constant is defined as '$.' prefixed to column-name.
{ "id" : 901, "firstname" : "John", "lastname" : "Doe", "phoneno" : "555-3762" }
SELECT U."id" , U."firstname" , U."lastname" , U."phoneno" FROM EMPLOYEE_TABLE E JSON_TABLE(E.jsondoc, 'strict $' COLUMNS( "id" INTEGER, "firstname" VARCHAR(20), "lastname" VARCHAR(20), "phoneno" VARCHAR(20)) ERROR ON ERROR) AS U