Re: Temporarily disable not null constraints - Mailing list pgsql-performance

From Justin Pryzby
Subject Re: Temporarily disable not null constraints
Date
Msg-id 20201203223436.GT24052@telsasoft.com
Whole thread Raw
In response to Temporarily disable not null constraints  (Nagaraj Raj <nagaraj.sf@yahoo.com>)
List 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 by date:

Previous
From: Milos Babic
Date:
Subject: Re: Temporarily disable not null constraints
Next
From: aditya desai
Date:
Subject: Re: Pg_locks and pg_stat_activity