我正在尝试使用 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,但它(仅)遗漏了它。 我在这里缺少什么?
最佳答案
因为你的标识符是大写的,你应该使用双引号来获取它们里面的值:
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);
关于json - 在 Postgres jsonb_to_recordset() 中显示为 NULL 的键值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42914494/