I am trying to query a H2 table using JSON_OBJECT. but the error message says, there is no function like JSON_OBJECT.
I am trying something like:
SELECT JSON_OBJECT(LABEL , DETAIL_DATA )
FROM DB.REQUEST_DETAILS ;
The error message is: 'Function "JSON_OBJECT" not found; ' How should i use JSON_OBJECT?
My requirement is, we are storing a set of values as a column for "Key" and a Column for "Value". This is done to support different requests with different keys. For example the below table:
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
<table>
<th> label </th>
<th> details </th>
<tr>
<td> name </td>
<td> abc </td>
</tr>
<tr>
<td> email </td>
<td> abc@email </td>
</tr>
<tr>
<td> phone </td>
<td> 123 </td>
</tr>
</table>
<p> This needs to be converted as:
<table>
<th> Name </th>
<th> Email</th>
<th> Phone> </th>
<tr>
<td> abc </td>
<td> email </td>
<td> abc@email </td>
</tr>
</table>
Is there a better query which gets the data from label-details to inverted format? Thanks in advance
Make sure that you use a recent version of H2. This function was introduced in H2 1.4.200, older versions don't have it. (H2 1.4.200 is too old and isn't supported, it will be better to use some newer version).
Fix its syntax in your query. It has a very special grammar in the SQL Standard:
JSON_OBJECT(LABEL : DETAIL_DATA)
-- or
JSON_OBJECT(LABEL VALUE DETAIL_DATA)
-- or
JSON_OBJECT(KEY LABEL VALUE DETAIL_DATA)
See also documentation of H2: https://h2database.com/html/functions.html#json_object