Sulbigar Shanawaz
Sulbigar Shanawaz

Reputation: 159

Postgresql: Passing result of a select query to jsonb_to_recordset is not working

I have a table with the below format.

TableName: data

data table

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

enter image description here

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

Answers (1)

user330315
user330315

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

Related Questions