json - 在 Postgres jsonb_to_recordset() 中显示为 NULL 的键值

标签 json postgresql

我正在尝试使用 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/

相关文章:

postgresql - 如何在 Postgresql 的别名列中使用 order by case?

c# - 反序列化时如何忽略下划线

java - 如何从 JSONObject 获取所有数组?

php - 如何在 dart 的 Future 函数中从 JSON 创建一个类对象?

java - Jackson JSON 使用注释进行 pretty-print

java - 如何使用 hibernate 自动生成额外的序列?

sql - PostgreSQL 9.5 在多次出现的键上插入数据

sql - Postgresql 复制槽错误 postgresql

python - 在 Mac OS X 上安装 libpq-dev

python - 在 Django 中使用 Python 解析 JSON 文件