【发布时间】:2022-01-14 16:57:55
【问题描述】:
有了这张桌子
CREATE TABLE IF NOT EXISTS actions (
action_id UUID NOT NULL DEFAULT uuid_generate_v4(),
inputs JSONB[] NOT NULL DEFAULT ARRAY[]::JSONB[]
)
我正在尝试插入此数据
INSERT INTO actions (
action_id,
inputs
)
VALUES (
'41fc94af-2f4e-424f-acde-641bb63f4b82',
array['{"type":"string"}{"displayName":"Base OAuth URL","type":"string","description":"Base OAuth URL"}']::jsonb[]
);
但得到错误
ERROR: invalid input syntax for type json
LINE 7: array['{"type":"string"}{"di...
^
DETAIL: Expected end of input, but found "{".
CONTEXT: JSON data, line 1: {"type":"string"}{...
这也行不通
INSERT INTO actions (
action_id,
inputs
)
VALUES (
'41fc94af-2f4e-424f-acde-641bb63f4b82',
[{"type":"string"}{"displayName":"Base OAuth URL","type":"string","description":"Base OAuth URL"}]::jsonb[]
);
【问题讨论】:
-
您正在混合 Postgres
array和jsonb类型。你真的想要jsonb对象的 Postgresarray还是存储为jsonb的 JSON 对象数组? -
避免
jsonb[],它很难索引并且处理起来很混乱 -
我同意另外两个。
jsonb[]在我看来毫无意义
标签: postgresql jsonb