column DEFAULTs and prepared statements - Mailing list pgsql-hackers

From Florian G. Pflug
Subject column DEFAULTs and prepared statements
Date
Msg-id 4B05FD2E.5030101@phlo.org
Whole thread Raw
List pgsql-hackers
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


pgsql-hackers by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: Summary and Plan for Hot Standby
Next
From: Kenneth Marshall
Date:
Subject: Re: Union test case broken in make check?