Re: Proposition for autoname columns

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Proposition for autoname columns
Дата
Msg-id CAKFQuwZKbwiyEPOQG6o5wQ595XUCL1X3fz+1ce9c6hG2KLj9AA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Proposition for autoname columns  (Bruce Momjian <bruce@momjian.us>)
Список pgsql-hackers
On Wed, Nov 11, 2020 at 8:56 AM Bruce Momjian <bruce@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.

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Magnus Hagander
Дата:
Сообщение: Re: Prevent printing "next step instructions" in initdb and pg_upgrade
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: Prevent printing "next step instructions" in initdb and pg_upgrade