我的地址栏使用以下格式存储为JSON:
{
"Street1": "800 Smithe St",
"Street2": null,
"City": "Vancouver",
"Region": null,
"State": "BC",
"Zip": "V6Z 2E1"
}
如何将列值更改为驼峰大小写/小写,因此它们看起来像这样?
{
"street1": "800 Smithe St",
"street2": null,
"city": "Vancouver",
"region": null,
"state": "BC",
"zip": "V6Z 2E1"
}
答案 0 :(得分:2)
with j(j) as ( values ($$
{
"Street1": "800 Smithe St",
"Street2": null,
"City": "Vancouver",
"Region": null,
"State": "BC",
"Zip": "V6Z 2E1"
}
$$::jsonb))
select json_object_agg(lower(key), value)
from j, jsonb_each(j) je
group by j;
json_object_agg
-----------------------------------------------------------------------------------------------------------------------------
{ "zip" : "V6Z 2E1", "city" : "Vancouver", "state" : "BC", "region" : null, "street1" : "800 Smithe St", "street2" : null }