我正在尝试使用jsonb_to_recordset()提取键值。这就是原始jsonb数组的样子:
select journal.id as journal_id, journal.data::jsonb#>'{context,data,files}' as filelist from journal where id = 'aqpubr0ivqaaolpr4lp0';
结果是:
[{"id": 0, "name": "MNDA_Template.doc", "extension": ".doc", "transferId": "aqpl61ple38cdebbrmgg"}]
如您所见,密钥transferId具有值。但是当我使用jsonb_to_recordset()提取它时,它会提取除transferId之外的所有其他键值:
select j.id as journal_id,d.name as file_name,d.extension as ext,d.transferId as TxferId from journal j cross join lateral jsonb_to_recordset(j.data#>'{context, data, files}') as d(id int, name text, extension text, transferId text) where j.id = 'aqpubr0ivqaaolpr4lp0';
我明白了:
journal_id | file_name | ext | txferId
aqpubr0ivqaaolpr4lp0 | MNDA_Template.doc | .doc | (NULL)
虽然我在结构中定义了transferId,但它(仅)错过了它。 我在这里缺少什么?
答案 0 :(得分:2)
因为您的标识符是用大写字母书写的,所以您应该使用双引号来获取其中的值:
select * from jsonb_to_recordset('[{"id": 0, "name": "MNDA_Template.doc", "extension": ".doc", "transferId": "aqpl61ple38cdebbrmgg"}]')
as d(id int, name text, extension text, "transferId" text);