尝试在 PostgreSQL 中查询 JSON 文档时出现语法错误



在我的 postgresql 9.6 上,我遇到了一个错误,创建了一个类似

create table jsonTest (id integer, data jsonb);

该表包含以下数据:

select * from jsonTest;
id |               data               
----+----------------------------------
1 | {"tags": ["AA", "BB", "CC"]}
2 | {"tags": ["BB", "DD"]}
2 | {"tags": ["CC"]}
4 | {"city": "austin", "tags": "EE"}
(4 rows)

但是当我尝试选择时,出现语法错误:

template1=# select * from jsonTest where data->>city = 'austin';
ERROR:  column "city" does not exist
LINE 1: select * from jsonTest where data->>city = 'austin';

有什么想法吗?多谢!

JSON 对象的->>运算符的正确操作数是text。使用撇号作为键,因为没有撇号,Postgres 会将名称解释为标识符(列名(:

data->>'city'

最新更新