Re: BUG #15579: Adding a column with default from configuration parameter fails on 11.1

Поиск
Список
Период
Сортировка
Искать
От
Andrew Gierth
Тема
Re: BUG #15579: Adding a column with default from configuration parameter fails on 11.1
Дата
Msg-id
87a7kcqmls.fsf@news-spur.riddles.org.uk
Ответ на
Список
Дерево обсуждения
BUG #15579: Adding a column with default from configuration parameterfails on 11.1 PG Bug reporting form <noreply@postgresql.org>
Re: BUG #15579: Adding a column with default from configuration parameter fails on 11.1 Tom Lane <tgl@sss.pgh.pa.us>
Re: BUG #15579: Adding a column with default from configurationparameter fails on 11.1 Andrew Dunstan <andrew@dunslane.net>
Re: BUG #15579: Adding a column with default from configuration parameter fails on 11.1 Tom Lane <tgl@sss.pgh.pa.us>
Re: BUG #15579: Adding a column with default from configurationparameter fails on 11.1 Andres Freund <andres@anarazel.de>
Re: BUG #15579: Adding a column with default from configurationparameter fails on 11.1 Andrew Dunstan <andrew@dunslane.net>
Re: BUG #15579: Adding a column with default from configuration parameter fails on 11.1 Andrew Gierth <andrew@tao11.riddles.org.uk>
Re: BUG #15579: Adding a column with default from configurationparameter fails on 11.1 Dmitry Dolgov <9erthalion6@gmail.com>
>>>>> "PG" == PG Bug reporting form  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)

В списке pgsql-bugs по дате отправления
От: PG Bug reporting form
Дата:
От: Thomas Munro
Дата:
FAQ