>>>>> "PG" == PG Bug reporting form <noreply@postgresql.org> writes:
PG> However, creating the table first and then adding the column does
PG> not work on 11.1. It used to work at least from version 9.3 to 10.
PG> create table t (x int);
PG> alter table t add c varchar(50) default
PG> current_setting('public.some_setting');
This used to work ONLY if the table is empty, since the alter table
would evaluate the expression once per row (and hence not evaluate it if
there are no rows).
On PG 11, the new fast-default stuff will evaluate the default once, if
it's not volatile, even if the table is empty. So this is an intended
change.
If you know that the table is empty when you do the alter table, you can
do this, which works on any pg version:
alter table t add c varchar(50),
alter column c set default current_setting('public.some_setting');
(if the table is not empty, then existing rows will get a null value in
column "c")
--
Andrew (irc:RhodiumToad)