【发布时间】:2018-06-17 08:51:26
【问题描述】:
看看我的 JSONB 字段
select internet_address from resporg_account_ids where id=3
=> [{"zone": "us-central1", "address": "127.0.0.1", "reserve": true}, {"zone": "us-east1", "address": "127.0.0.10", "reserve": true}
]
相关jsonb查询
select * from resporg_account_ids where internet_address <@ '[{"zone": "us-central1", "address": "127.0.0.1", "reserve": true}]'::jsonb;
还有这个
select * from resporg_account_ids where internet_address <@ '{"zone": "us-central1", "address": "127.0.0.1", "reserve": true}'::jsonb;
我在输出控制台中看不到任何结果。
另外,我想根据单个键查询它...
喜欢
select * from resporg_account_ids where internet_address->>address="127.0.0.1" and internet_address->>reserve=true
最后,
jsondb=# select version();
version
---------------------------------------------------------------------------------------------------------------
PostgreSQL 9.5.10 on x86_64-apple-darwin17.2.0, compiled by Apple LLVM version 9.0.0 (clang-900.0.38), 64-bit
(1 row)
注意:
第 1 部分:已解决,感谢 @mroman 指出。
【问题讨论】:
-
a <@ b表示 A 包含在 B 中,而不是 B 包含在 A 中。您可能需要翻转参数或使用@>。但我不确定这些操作数是否可以用于数组。
标签: postgresql postgresql-json