Re: [GENERAL] How to stop array_to_json from interpolating columnnames that weren't there - Mailing list pgsql-general

From Paul Jungwirth
Subject Re: [GENERAL] How to stop array_to_json from interpolating columnnames that weren't there
Date
Msg-id c9107d6f-7fd5-d16b-1ff3-0434c40a7f9d@illuminatedcomputing.com
Whole thread Raw
In response to [GENERAL] How to stop array_to_json from interpolating column names thatweren't there  (Guyren Howe <guyren@gmail.com>)
Responses Re: [GENERAL] How to stop array_to_json from interpolating columnnames that weren't there  (Guyren Howe <guyren@gmail.com>)
List pgsql-general
> which is great. I have an array of perfect JSON objects. Now I just need
> to turn that into a single JSON object.

I think you're saying you want it as a single JSON *array*, right? An
object of objects doesn't make sense. Assuming that's right, this seems
to work:

db1=# select json_agg(schemata) from schemata;
                                                  json_agg

----------------------------------------------------------------------------------------------------------

[{"catalog_name":"db1","schema_name":"information_schema","schema_name_address":"/information_schema"},
{"catalog_name":"db1","schema_name":"pg_catalog","schema_name_address":"/pg_catalog"},
{"catalog_name":"db1","schema_name":"pg_temp_1","schema_name_address":"/pg_temp_1"},
{"catalog_name":"db1","schema_name":"pg_toast","schema_name_address":"/pg_toast"},
{"catalog_name":"db1","schema_name":"pg_toast_temp_1","schema_name_address":"/pg_toast_temp_1"},
{"catalog_name":"db1","schema_name":"public","schema_name_address":"/public"}]
(1 row)

Paul


pgsql-general by date:

Previous
From: Igor Korot
Date:
Subject: Re: [GENERAL]
Next
From: Guyren Howe
Date:
Subject: Re: [GENERAL] How to stop array_to_json from interpolating columnnames that weren't there