Re: Schema variables - new implementation for Postgres 15

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Schema variables - new implementation for Postgres 15
Дата
Msg-id 4169150.1716398746@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Schema variables - new implementation for Postgres 15  (Peter Eisentraut <peter@eisentraut.org>)
Ответы Re: Schema variables - new implementation for Postgres 15
Re: Schema variables - new implementation for Postgres 15
Список pgsql-hackers
Peter Eisentraut <peter@eisentraut.org> writes:
> On 18.05.24 13:29, Alvaro Herrera wrote:
>> I want to note that when we discussed this patch series at the dev
>> meeting in FOSDEM, a sort-of conclusion was reached that we didn't want
>> schema variables at all because of the fact that creating a variable
>> would potentially change the meaning of queries by shadowing table
>> columns.  But this turns out to be incorrect: it's_variables_  that are
>> shadowed by table columns, not the other way around.

> But that's still bad, because seemingly unrelated schema changes can 
> make variables appear and disappear.  For example, if you have
>     SELECT a, b FROM table1
> and then you drop column b, maybe the above query continues to work 
> because there is also a variable b.

Yeah, that seems pretty dangerous.  Could we make it safe enough
by requiring some qualification on variable names?  That is, if
you mean b to be a variable, then you must write something like

    SELECT a, pg_variables.b FROM table1

This is still ambiguous if you use "pg_variables" as a table alias in
the query, but the alias would win so the query still means what it
meant before.  Also, table aliases (as opposed to actual table names)
don't change readily, so I don't think there's much risk of the query
suddenly meaning something different than it did yesterday.

            regards, tom lane



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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: Virtual generated columns
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: Virtual generated columns