Quantcast
Channel: PostgreSQL output to JSON object/array - Stack Overflow
Viewing all articles
Browse latest Browse all 2

PostgreSQL output to JSON object/array

$
0
0

I'm running PostgreSQL and are trying to convert this:

SELECT car_id AS id, car_model AS model FROM cars

into this:

[{ "id" : 123, "model" : "Fiat" }, {"id": 124, "model": "BMW"}, ...]

I've tried:

SELECT json_agg(
           json_build_object(car_id AS id),
           json_build_object(car_model AS model)
       ) FROM cars

and a lot other stuff, but seems to be stuck


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images