我在 postgres 中有一個表,其中web包含 jsonb 型別的列。它包含重復的值,如下所示。我想從陣列中洗掉所有重復項。你能幫忙嗎?
Jsonb 列只有 2 行以下的值
["test.com","test.com","abc.com"]
["google.com","fb.com","google.com"]
所需輸出
["test.com","abc.com"]
["google.com","fb.com"]
uj5u.com熱心網友回復:
沒有內置任何東西,但是撰寫一個函式很容易:
create function unique_elements(p_input jsonb)
returns jsonb
as
$$
select jsonb_agg(distinct t.element)
from jsonb_array_elements(p_input) as t(element);
$$
language sql
immutable;
然后像這樣使用它:
select unique_elements(web)
from the_table;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/526448.html
