【发布时间】:2016-03-18 15:57:56
【问题描述】:
我有一个包含 JSON 数据类型字段的表。我想选择这个 JSON 字段中存在的值:
dev=> select id, command from statemachine_history;
id | command
------+--------------------------------------------------------------------------------------
1 | {"Common\\Accounting\\StateMachine\\Command\\CreateDebitorCommand":true}
2 | []
3 | {"Common\\Message\\StateMachine\\MessageSendOutCommand":true}
4 | []
5 | {"Common\\Message\\StateMachine\\MessageSendOutCommand":false}
6 | {"Common\\Message\\StateMachine\\MessageCheckRetryCommand":true}
7 | {"Common\\Newsletter\\Command\\IssueConfirmationRequest":true}
8 | {"Common\\Customer\\Command\\CustomerActivateCommand":true}
9 | {"Common\\Customer\\Command\\CustomerRegisterCommand":true}
10 | {"Common\\Accounting\\StateMachine\\Command\\CreateDebitorCommand":true}
11 | []
12 | {"Common\\Message\\StateMachine\\MessageSendOutCommand":true}
13 | {"Common\\Accounting\\StateMachine\\Command\\CreateDebitorCommand":true}
1033 | []
14 | []
15 | {"Common\\Message\\StateMachine\\MessageSendOutCommand":true}
16 | {"Common\\Customer\\Command\\CustomerActivateCommand":true}
17 | {"Common\\Customer\\Command\\CustomerRegisterCommand":true}
18 | []
19 | {"Common\\Message\\StateMachine\\MessageSendOutCommand":false}
20 | {"Common\\Message\\StateMachine\\MessageCheckRetryCommand":true}
21 | {"INTPASS\\Appointment\\StateMachine\\Command\\FinalizeBookingsCommand":true}
22 | {"INTPASS\\Appointment\\StateMachine\\Command\\FinalizeBookingsCommand":true}
我想知道如何访问这个数组的键。具体来说,我想从该表中选择命令字段中存在某些值的位置。
我尝试了以下方法,但它不起作用:
SELECT * FROM statemachine_history WHERE command->'key' = 'Common\\Message\\StateMachine\\MessageSendOutCommand'
【问题讨论】:
标签: sql json database postgresql psql