PostgreSQL:将选择查询的结果传递给jsonb_to_recordset无效

问题描述

我有一个表格,格式如下。

TableName:数据

data table

我在下面的查询提取data2 jsonb。

select comment->data2 from data where id=1

我必须像记录集那样获取生成的jsonb

enter image description here

我认为jsonb_to_recordset将有助于按预期方式产生结果,但是当我尝试运行以下查询

select * from json_to_recordset(select comment->data2 from data where id=1) as x(valueId text,valueType text);

但是我得到以下错误

Query 1 ERROR: ERROR:  Syntax error at or near "select"
LINE 1: select * from json_to_recordset(select comment->data2...

有人可以指导我在这里做错什么吗?

解决方法

您需要将内部选择括在括号中

select * 
from json_to_recordset( (select comment->data2 from data where id=1) ) as x(valueId text,valueType text);