首页 > 解决方案 > 为什么插入语句在试图插入 json 的 postgres 中不起作用?

问题描述

为什么我的插入语句不起作用?

这是我的代码 http://sqlfiddle.com/#!17

create table json_check (
  id serial primary key not null ,
  body jsonb
)

insert into json_check (body)
values ('{

"test":"naveeb",
"data":"{'a':'ss'}"}')

它向我显示了一个语法错误。

标签: sqljsonpostgresql

解决方案


看来您的 JSON 无效。

insert into json_check (body)
values ('{
    "test": "naveeb",
    "data": {
        "a": "ss"
    }
}');

您可以在https://jsonlint.com/上检查您的 JSON 状态。

运行示例粘贴在以下链接:

http://sqlfiddle.com/#!17/80ca3/6


推荐阅读