Re: Temporarily disable not null constraints

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Nagaraj Raj <nagaraj(dot)sf(at)yahoo(dot)com>
Cc: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: Re: Temporarily disable not null constraints
Date: 2020-12-03 22:34:36
Message-ID: 20201203223436.GT24052@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 is found 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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message aditya desai 2020-12-04 06:13:03 Re: Pg_locks and pg_stat_activity
Previous Message Milos Babic 2020-12-03 20:13:46 Re: Temporarily disable not null constraints