【发布时间】:2019-08-05 15:19:40
【问题描述】:
我正在尝试使用 PostgreSQL 中具有 json 类型的数组列 NOTES 查询表 USERS。
[{"notes":"testing note 1","createdby":"fname1, lname1","createddt":"2018-09-05T13:28:32-07:00"},
{"notes":"testing note 2","createdby":"fname2, lname2","createddt":"2018-09-05T14:40:06-07:00"},
{"notes":"testing note 3","createdby":"fname3, lname3","createddt":"2018-09-06T16:08:52-07:00"}]
我正在寻找每个笔记的 createddt。
我尝试了几种方法,但始终无法理解。
select json_array_elements(notes) as createddt from USERS -- gives me all 3 of the arrays.
select json_array_elements(notes->>'createddt') as createddt from USERS -- gives me a connection error.
【问题讨论】:
-
提醒一下:如果您的数据库方案过于复杂而无法执行如此简单的任务,您应该考虑重构该方案;) 规范化的发明是有原因的......
-
我支持它,但我没有创建它,只是做客户支持故障排除。
标签: arrays json postgresql