我有一张桌子"产品"它们有多列,在这些列"规范"是json,我有这个数据:
[
{
"en":"Weight",
"ar":"الوزن",
"value":"100"
},
{
"en":"Height",
"ar":"الارتفاع",
"value":"300"
}
]
我只需要获得" en,value"或" ar,价值"除了表格的剩余字段之外,还来自该字段。
答案 0 :(得分:0)
让我们试试这个
select column_names,
--all column names you can left "specifications" column
(select string_agg(v,',') from
(select '(' || (val->>'en')::text || ',' || (val->>'value')::text || ')' as v
--You can put whatever json key-value you want here
from (select value as val from
(select value from json_array_elements("specifications"))))) from "products"
希望它适合你。