Re: Temporarily disable not null constraints

Поиск
Список
Период
Сортировка
От Justin Pryzby
Тема Re: Temporarily disable not null constraints
Дата
Msg-id 20201203223436.GT24052@telsasoft.com
обсуждение исходный текст
Ответ на Temporarily disable not null constraints  (Nagaraj Raj <nagaraj.sf@yahoo.com>)
Список pgsql-performance
On Thu, Dec 03, 2020 at 07:58:15PM +0000, Nagaraj Raj wrote:
> Can we disable not null constraints temporarily in the session-based transaction, like we disable FK constraints? 

If you're trying to temporarily violate the not-null constraint..
I don't know if it's a good idea..

..but maybe this feature in v12 helps you:

https://www.postgresql.org/docs/12/sql-altertable.html
| Ordinarily this is checked during the ALTER TABLE by scanning the entire table; however, if a valid CHECK constraint
isfound which proves no NULL can exist, then the table scan is skipped.
 

When you're done violating constraints, you can
ALTER .. ADD CONSTRAINT .. CHECK (.. IS NOT NULL) NOT VALID, and then
ALTER .. VALIDATE CONSTRAINT, and then ALTER column SET NOT NULL.

-- 
Justin



В списке pgsql-performance по дате отправления:

Предыдущее
От: Milos Babic
Дата:
Сообщение: Re: Temporarily disable not null constraints
Следующее
От: aditya desai
Дата:
Сообщение: Re: Pg_locks and pg_stat_activity