插入到 jsonb[] 列

Insert into jsonb[] column

有了这个table

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[]
);

我没听懂你的意思。可以肯定的是,您在 array[..] 中写的既不是单个 json 也不是 json.

的数组

如果{"type":"string"}{"displayName":"Base OAuth URL","type":"string","description":"Base OAuth URL"}是两个不同的对象那么你必须写:

array[
    '{"type":"string"}',
    '{"displayName":"Base OAuth URL","type":"string","description":"Base OAuth URL"}'
    ]::jsonb[]