Thread: column DEFAULTs and prepared statements

column DEFAULTs and prepared statements

From
"Florian G. Pflug"
Date:
Hi

While trying to come up with a patch to handle domain DEFAULTs in
plpgsql I've stumbled across the following behavior regarding domain
DEFAULTs and prepared statements.

session 1: create domain myint as int default 0 ;
session 1: create table mytable (i myint) ;
session 2: prepare ins as insert into mytable (i) values (default);
session 2: execute ins;
session 1: alter domain myint set default 1;
session 2: execute ins;

select * from mytable returns: i
--- 0 0


while I'd have expected: i
--- 0 1

After doing the same without using a domain
session 1: create table mytable (i myint default 0) ;
session 2: prepare ins as insert into mytable (i) values (default);
session 2: execute ins;
session 1: alter table mytable alter column i default 1;
session 2: execute ins;

select * from mytable returns: i
--- 0 1

As far as I understand the code this happens because the dependency on
the domain (for the default value) is not recorded in the plan cache
entry. This would imply that the same error also occurs if the INSERT
happens from a pl/pgsql function instead of a manually prepared
statement, but I haven't tested that.

If someone gives me a general idea where to start, I could try to come
up with a patch

best regards,
Florian Pflug