Re: Temporarily disable not null constraints

Поиск
Список
Период
Сортировка
Искать
От
Milos Babic
Тема
Re: Temporarily disable not null constraints
Дата
Msg-id
CAPVD16t0UPFiSPJrpefObeU5c60BEhxP7SuA-dPHGAcHSChZwg@mail.gmail.com
Ответ на
Список
Дерево обсуждения
Temporarily disable not null constraints Nagaraj Raj <nagaraj.sf@yahoo.com>
Re: Temporarily disable not null constraints Justin Pryzby <pryzby@telsasoft.com>
Re: Temporarily disable not null constraints Michael Lewis <mlewis@entrata.com>
Re: Temporarily disable not null constraints Milos Babic <milos.babic@gmail.com>
generally, you shouldn't be disabling your constraints, especially if you are having multiple parallel processes accessing your db.
instead, you should create them DEFERRABLE and have them checked at the end of your transaction.

regarding your question about NOT NULL: it is not possible to have it deferred (please check this page: https://www.postgresql.org/docs/13/sql-set-constraints.html)
you may alter your column, remove it, and then get it back, but still all rows will have to be checked, which I doubt you would like to see on a large table.

regards, milos



On Thu, Dec 3, 2020 at 9:00 PM Nagaraj Raj <nagaraj.sf@yahoo.com> wrote:
Hi,

Can we disable not null constraints temporarily in the session-based transaction, like we disable FK constraints? 

SET session_replication_role = ‘replica’; 
alter table table_name disable trigger user;”

above two options are working for unique constraints violation exception. 

Thanks,
Rj


В списке pgsql-performance по дате отправления
От: Michael Lewis
Дата:
От: Justin Pryzby
Дата:
FAQ