Another issue in default-values patch: defaults expanded too soon

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Another issue in default-values patch: defaults expanded too soon
Дата
Msg-id 15214.1229459100@sss.pgh.pa.us
обсуждение исходный текст
Ответы Re: Another issue in default-values patch: defaults expanded too soon  ("David E. Wheeler" <david@kineticode.com>)
Re: Another issue in default-values patch: defaults expanded too soon  (Josh Berkus <josh@agliodbs.com>)
Re: Another issue in default-values patch: defaults expanded too soon  ("Robert Haas" <robertmhaas@gmail.com>)
Список pgsql-hackers
Consider

create function foo(f1 int, f2 int = 42, f2 int = 43) ...
create view v1 as select foo(11);

In CVS HEAD this gives

regression=# \d v1      View "public.v1"Column |  Type   | Modifiers 
--------+---------+-----------foo    | integer | 
View definition:SELECT foo(11, 42, 43) AS foo;

which is an accurate representation of the truth: if you change the
defaults for function foo, v1 will keep on calling it with the old
default values.

Does anyone think this is either unsurprising or desirable?

I'm not sure we can do much to fix it, though.  It'd probably be
possible to have the rewriter or planner insert the default expressions,
instead of the parser; but that creates its own issues.  Suppose I had
v1 defined as above and then did

create or replace function foo(f1 int, f2 int, f2 int = 43) ...

ie, remove one or more default expressions.  *This function definition
no longer matches the original call*.  If we did plan-time insertion of
defaults we'd have little choice but to fail when v1 is executed,
because there'd be no principled way to insert a default for f2.
Treating the defaults as being inserted at parse time at least ensures
that v1's call to foo still works.

This at least needs documentation, I think.

Comments?
        regards, tom lane


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

Предыдущее
От: Robert Lor
Дата:
Сообщение: Re: DTrace probes patch
Следующее
От: "David E. Wheeler"
Дата:
Сообщение: Re: Another issue in default-values patch: defaults expanded too soon