将 postgres 数组转换为 jsonb

pri*_*ula 4 postgresql

我们如何将 postgres 数组 :- 转换ARRAY['{"id": "1"}', '{"id": "2"}']为 JSONB'[{"id": "1"}, {"id": "2"}]'

小智 14

array_to_json 函数通过强制转换为 jsonb 来完成此操作。

例子:select array_to_json(ARRAY['{"id": "1"}', '{"id": "2"}'])::jsonb;