Postgresql:将select查询的结果传递给jsonb_to_记录集无效

Postgresql:将select查询的结果传递给jsonb_to_记录集无效,postgresql,jsonb,Postgresql,Jsonb,我有一张表格,格式如下 表名:数据 我有下面的查询来提取data2jsonb select comment->data2 from data where id=1 我必须像记录集一样获取结果jsonb 我认为jsonb_to_记录集将有助于产生预期的结果,但当我尝试运行下面的查询时 select * from json_to_recordset(select comment->data2 from data where id=1) as x(valueId text, valu

我有一张表格,格式如下

表名:数据

我有下面的查询来提取
data2
jsonb

select comment->data2 from data where id=1
我必须像记录集一样获取结果jsonb

我认为
jsonb_to_记录集
将有助于产生预期的结果,但当我尝试运行下面的查询时

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括在括号中:

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

错误消失了,但结果是一个空表。还有什么需要做的吗?这是如此令人困惑的例子中提供的工程预期<代码>选择*从jsonb_到_记录集('[{“a”:1,b:“foo”},{“a:“2”,“c:“bar”}])作为x(a int,b text)虽然我的用例的jsonb(主要问题中的示例是sample,这更接近真实数据)即使以最简单的形式也无法工作<代码>选择*从jsonb_到_记录集('[{“fieldId”:“1”,“fieldType”:“selection”,“fieldValue”:“6120”},{“fieldId”:“2”,“fieldType”:“selection”},{“fieldId”:“3”,“fieldType”:“text”,“fieldValue”:“Sameple text”},{“fieldId”:“4”,“fieldType”:“text”,“fieldValue”:“project code”}])x(fieldId文本,fieldType文本,fieldValue文本)好的,我刚刚发现如果键完全小写,它会像预期的那样工作……不知道为什么会这样,也不知道这是否是postgresql中的错误。下面的方法很有效<代码>选择*从json_到_记录集('[{“fieldid”:“1”,“fieldtype”:“selection”,“fieldvalue”:“6120”},{“fieldid”:“2”,“fieldtype”:“selection”},{“fieldid”:“3”,“fieldtype”:“text”,“fieldvalue”:“Sameple text”},{“fieldid”:“4”,“fieldtype”:“text”,“fieldvalue”:“project code”}])x(fieldid文本,fieldtype文本,fieldvalue文本)使用“”按原样映射字段名<代码>x(“字段ID”文本、“字段类型”文本、“字段值”文本)