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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -