On Wed, Nov 11, 2020 at 8:56 AM Bruce Momjian <br...@momjian.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.

Reply via email to