Re: Proposition for autoname columns

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Eugen Konkov <kes-kes(at)yandex(dot)ru>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Proposition for autoname columns
Date: 2020-11-11 16:39:14
Message-ID: CAKFQuwZKbwiyEPOQG6o5wQ595XUCL1X3fz+1ce9c6hG2KLj9AA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Nov 11, 2020 at 8:56 AM Bruce Momjian <bruce(at)momjian(dot)us> wrote:

> > It would be useful if the name of column will be autoassigned based on
> > name of json key. Like at next query:
> >
> > tucha=# select info->>'suma' as suma, docn from document order by id
> desc limit 5;
> > suma | docn
> > --------+------
>
> > Would it be useful this auto assigned name for column from json?
>
> I think we could do it, but it would only work if the column was output
> as a single json value, and not a multi-key/value field. I am afraid if
> we tried to do it, the result would be too inconsistent to be useful.
>

Doing it seems problematic given the nature of SQL and existing means to
assign names to columns. If it can be done I don't see how the output
value would make any difference. What is being asked for is the simple
textual value on the right side of the ->> (and other similar) operators to
be converted into a column name. I could image doing this at rewrite time
by saying (in parse terms):

info->>'suma to' becomes info->>'suma' AS "suma to" (specifically, add AS,
double-quote the literal and stick it after the AS).

If {AS "suma to"} isn't valid syntax for some value of "suma to" just drop
the attempt and move on.

I agree that this feature would be useful.

David J.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2020-11-11 16:42:26 Re: Prevent printing "next step instructions" in initdb and pg_upgrade
Previous Message Magnus Hagander 2020-11-11 16:39:10 Re: Prevent printing "next step instructions" in initdb and pg_upgrade