在PostgreSQL 9.6中访问json类型数据时出错

我已经在PostgreSQL 9.6服务器中创建了一个包含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行:信息->> “客户” AS客户 ^提示:没有运算符匹配给定的名称和参数类型。您可能需要添加显式类型转换。的SQL 状态:42883字符:16

有人可以建议,对此我该怎么办?

xukaizhan 回答:在PostgreSQL 9.6中访问json类型数据时出错

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2791129.html

大家都在问