如何通过“|”连接 json 数组值?
How to concatenate json array values via "|"?
我有 jsonb 格式的列。列名是“column1”,table 是“table1”
{
.....
"source_types": {
"source_type_os": [ ,
1,3,5
],
....
},
....
}
我可以像“[1,3,5]”这样的数组字符串,但我需要得到像 1|3|5
这样的东西
我试过这个代码
select ....
t1.column1::jsonb #>>'{source_types,source_type_os}' as "test", <--here the problem
....
from table1 t1
where ....;
select ....
string_agg(c.col, '|') as "test"
from table1 as t1
cross join lateral jsonb_array_elements_text(t1.column1::jsonb #>>'{source_types,source_type_os}') as c(col)
group by t1
select ....
replace(trim(both '[]' from t1.column1::jsonb #>>'{source_types,source_type_os}'),',','|') as "test",
....
from table1 t1
where ....;
我有 jsonb 格式的列。列名是“column1”,table 是“table1”
{
.....
"source_types": {
"source_type_os": [ ,
1,3,5
],
....
},
....
}
我可以像“[1,3,5]”这样的数组字符串,但我需要得到像 1|3|5
这样的东西我试过这个代码
select ....
t1.column1::jsonb #>>'{source_types,source_type_os}' as "test", <--here the problem
....
from table1 t1
where ....;
select ....
string_agg(c.col, '|') as "test"
from table1 as t1
cross join lateral jsonb_array_elements_text(t1.column1::jsonb #>>'{source_types,source_type_os}') as c(col)
group by t1
select ....
replace(trim(both '[]' from t1.column1::jsonb #>>'{source_types,source_type_os}'),',','|') as "test",
....
from table1 t1
where ....;