Reputation: 159
I have a table with the below format.
TableName: data
I have the below query to extract the data2
jsonb.
select comment->data2 from data where id=1
I have to fetch the resulting jsonb as recordset like
I figured that jsonb_to_recordset
will help in yielding the result as expected but when I tried to run the below query
select * from json_to_recordset(select comment->data2 from data where id=1) as x(valueId text, valueType text);
but i get the below error
Query 1 ERROR: ERROR: syntax error at or near "select"
LINE 1: select * from json_to_recordset(select comment->data2...
Can someone guide on what I'm doing wrong here?
Upvotes: 1
Views: 2360
Reputation:
You need to enclose the inner select in parentheses:
select *
from json_to_recordset( (select comment->data2 from data where id=1) ) as x(valueId text, valueType text);
Upvotes: 3