postgresql 杰森布?不管用
postgresql Jsonb ? is not working
我使用的是 postgres 9.4,我有一个 table test_table,其中的定义是:
id (primary key) integer, meta_data json, version integer
Table数据如下:
1;"{"id":99,"file_name":"test.pdf"}";0
2;"{"id":101,"nest1":{"nest_name_1":"oxford"},"file_name":"test2.pdf"}";0
我想找到所有包含关键字 oxford 的主键。所以预期结果是 2。
我仍在努力寻找解决方案,我正在尝试类似的方法:
select * from test_table where meta_data ? 'oxford'
给我:
Error: operator does not exist: json ? unknown
这让我很困惑。肯定 postgresql 9.4 有?运营商对吗?发生了什么事?
有人能帮帮我吗
提前致谢
运算符 ?
适用于 jsonb
,因此您的查询应为:
select * from test_table where meta_data::jsonb ? 'oxford';
请注意,查询不会找到任何行,因为值 'oxford'
在嵌套对象中。
我使用的是 postgres 9.4,我有一个 table test_table,其中的定义是:
id (primary key) integer, meta_data json, version integer
Table数据如下:
1;"{"id":99,"file_name":"test.pdf"}";0
2;"{"id":101,"nest1":{"nest_name_1":"oxford"},"file_name":"test2.pdf"}";0
我想找到所有包含关键字 oxford 的主键。所以预期结果是 2。
我仍在努力寻找解决方案,我正在尝试类似的方法:
select * from test_table where meta_data ? 'oxford'
给我:
Error: operator does not exist: json ? unknown
这让我很困惑。肯定 postgresql 9.4 有?运营商对吗?发生了什么事?
有人能帮帮我吗
提前致谢
运算符 ?
适用于 jsonb
,因此您的查询应为:
select * from test_table where meta_data::jsonb ? 'oxford';
请注意,查询不会找到任何行,因为值 'oxford'
在嵌套对象中。