Re: psql JSON output format - Mailing list pgsql-hackers

From Christoph Berg
Subject Re: psql JSON output format
Date
Msg-id Za_dGsUW4qjOf-E7@msg.df7cb.de
Whole thread Raw
In response to Re: psql JSON output format  (Laurenz Albe <laurenz.albe@cybertec.at>)
Responses Re: psql JSON output format
List pgsql-hackers
Re: Laurenz Albe
> I am kind of unhappy about this change.  It seems awkward and undesirable
> so have JSON values decorated with weird quoting in JSON output.
> I understand the motivation, but I bet it's not what will make users
> happy.

Well, why stop at JSON, and not represent any array type as a JSON
array? Compound types could be transformed into JSON objects. Custom
data types could add hooks for their own custom JSON representation.

I'd just stop the flood right before it starts...

The real reason I'd not want to go that route is because I need the
format to be round-trip safe for the "\gedit" patch, see the other
thread. We would have to transform JSON sub-parts back into PG's text
format. But there were already complaints that other patch is complex.
At the moment it's just strcmp-ing the text value before and after,
which is straighforward.

> If you need to disambiguate between SQL NULL and JSON null, my
> preferred solution would be to omit SQL NULL columns from the output
> altogether.

That works, but only by convention only.


Re: David G. Johnston
> I agree on distinguishing SQL via omission but I do think, almost
> regardless, that the output should include a metadata section that lists
> all of the actual columns in the result, the column position, and since we
> have the info available, the data type name and possibly OID.  Then any
> column name present in the metadata but that isn't a key name for a given
> object is known to have an SQL NULL as the value of that column in that row.

There are no comments in JSON.

Adding the info in-band would break the simple use case of using the
data as-is for further processing.

Christoph



pgsql-hackers by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: psql JSON output format
Next
From: Laurenz Albe
Date:
Subject: Re: psql JSON output format