【发布时间】:2019-08-22 19:21:27
【问题描述】:
我正在尝试从存储在 db 中的 jsonb 值类型中的 json 中的 int 的 jsonb 数组中删除 int 值。
我有一个 json 值,比如:
select '{"a":[1,3]}'::jsonb->'a'
?column?
----------
[1, 3]
(1 row)
我想从中删除“1”,就像这样:
select array_remove(ARRAY[1,1,2,3], 1);
array_remove
--------------
{2,3}
(1 row)
但如果我这样做:
select array_remove(array('{"a":[1,3]}'::jsonb->'a'), 1);
或:
select array_remove('{"a":[1,3]}'::jsonb->'a'::text::int[], 1);
我有如下错误:
operator does not exist: jsonb -> integer[]
如何将 json 值转换为数组以从中删除值?
【问题讨论】:
标签: arrays json postgresql jsonb