PostgreSQL table to json -
PostgreSQL table to json -
i have table
key | value -----+------- | "foo" b | "bar"
how can result
{"a": "foo", "b": "bar"}
it doesn't work with
select array_to_json(array_agg(t)) table t; -- [{"key": "a", "value": "foo"}, {"key": "b", "value": "bar"}]
can help me?
postgresql ≥ 9.4 :
select json_object(array_agg(key), array_agg(value)) t; ┌────────────────────────────┐ │ json_object │ ├────────────────────────────┤ │ {"a" : "foo", "b" : "bar"} │ └────────────────────────────┘ (1 row)
json postgresql
Comments
Post a Comment