在postgreSQL 9.6中访问json类型数据时出错
我在PostgreSQL 9.6 server中创建了一个包含在postgreSQL 9.6中访问json类型数据时出错,sql,json,postgresql,postgresql-9.6,Sql,Json,Postgresql,Postgresql 9.6,我在PostgreSQL 9.6 server中创建了一个包含JSON数据的表“orders”,如下所示: CREATE TABLE orders ( ID serial NOT NULL PRIMARY KEY, info json NOT NULL ); 插入数据: INSERT INTO orders (info) VALUES ( '{ "customer": "Lily Bush", "items": {"product": "Diaper","qty"
JSON
数据的表“orders”,如下所示:
CREATE TABLE orders (
ID serial NOT NULL PRIMARY KEY,
info json NOT NULL
);
插入数据:
INSERT INTO orders (info)
VALUES
(
'{ "customer": "Lily Bush", "items": {"product": "Diaper","qty": 24}}'
),
(
'{ "customer": "Josh William", "items": {"product": "Toy Car","qty": 1}}'
),
(
'{ "customer": "Mary Clark", "items": {"product": "Toy Train","qty": 2}}'
);
稍后,我将尝试使用以下选择查询访问数据:
SELECT
info ->> 'customer' AS customer
FROM
orders;
我希望这是我的输出:
Lily Bush
Josh William
Mary Clark
但我明白了:
错误:运算符不存在:json->>未知行2:info->>
“客户”作为客户
^提示:没有与给定名称和参数类型匹配的运算符。您可能需要添加显式类型转换。SQL
州:42883字符:16
有人能建议我该怎么做吗?对我来说很有用:我再试了一次,但没有成功。然后你做的事情与你展示给我们的不同。我把你的脚本复制到了dbfiddle站点,它运行起来没有问题(请参阅我第一条评论中的链接),是的,我看到了。我复制了您在那里运行的查询。我得到了与以前相同的错误。您可能没有实际使用9.6。
select version()
显示了什么?