From: | Florian Pflug <fgp(at)phlo(dot)org> |
---|---|
To: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
Cc: | Merlin Moncure <mmoncure(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: idea: allow AS label inside ROW constructor |
Date: | 2014-10-23 13:57:14 |
Message-ID: | FCA11004-4C08-4BE8-AEC4-A0F2F1325272@phlo.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Oct23, 2014, at 15:39 , Andrew Dunstan <andrew(at)dunslane(dot)net> wrote:
> On 10/23/2014 09:27 AM, Merlin Moncure wrote:
>> On Thu, Oct 23, 2014 at 4:34 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>>> postgres=# select row_to_json(row(10 as A, row(30 as c, 20 AS B) as x));
>>> row_to_json
>>> ------------------------------
>>> {"a":10,"x":{"c":30,"b":20}}
>>> (1 row)
>>>
>> wow -- this is great. I'll take a a look.
>>
>
> Already in 9.4:
>
> andrew=# select json_build_object('a',10,'x',json_build_object('c',30,'b',20));
> json_build_object
> ----------------------------------------
> {"a" : 10, "x" : {"c" : 30, "b" : 20}}
> (1 row)
> So I'm not sure why we want another mechanism unless it's needed in some other context.
I've wanted to name the field of rows created with ROW() on more than
one occasion, quite independent from whether the resulting row is converted
to JSON or not. And quite apart from usefulness, this is a matter of
orthogonality. If we have named fields in anonymous record types, we should
provide a convenient way of specifying the field names.
So to summarize, I think this is an excellent idea, json_build_object
non-withstanding.
best regards,
Florian Pflug
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2014-10-23 14:00:00 | Typo fixes for pg_recvlogical documentation |
Previous Message | Andrew Dunstan | 2014-10-23 13:39:50 | Re: idea: allow AS label inside ROW constructor |