From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: pgsql-bugs@lists.postgresql.org
To: fredrik.widlert@digpro.se
Subject: Re: BUG #15579: Adding a column with default from configuration parameter fails on 11.1
Date: Mon, 07 Jan 2019 19:53:21 +0000
Message-ID: <87a7kcqmls.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <15579-c1494c68abb011ec@postgresql.org>
References: <15579-c1494c68abb011ec@postgresql.org>
>>>>> "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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: andrew@tao11.riddles.org.uk, fredrik.widlert@digpro.se
Subject: Re: BUG #15579: Adding a column with default from configuration parameter fails on 11.1
In-Reply-To: <87a7kcqmls.fsf@news-spur.riddles.org.uk>
References: <15579-c1494c68abb011ec@postgresql.org> <87a7kcqmls.fsf@news-spur.riddles.org.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox