pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Justin Pryzby <pryzby@telsasoft.com>
To: Nagaraj Raj <nagaraj.sf@yahoo.com>
Cc: pgsql-performance@lists.postgresql.org
Subject: Re: Temporarily disable not null constraints
Date: Thu, 3 Dec 2020 16:34:36 -0600
Message-ID: <20201203223436.GT24052@telsasoft.com> (raw)
In-Reply-To: <815507272.4135293.1607025495638@mail.yahoo.com>
References: <815507272.4135293.1607025495638.ref@mail.yahoo.com>
	<815507272.4135293.1607025495638@mail.yahoo.com>

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





view thread (4+ messages)

Message-ID: <20201203223436.GT24052@telsasoft.com>
Permalink:  ../20201203223436.GT24052@telsasoft.com/
Also on:    postgresql.org/message-id/20201203223436.GT24052@telsasoft.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: pryzby@telsasoft.com, nagaraj.sf@yahoo.com, pgsql-performance@lists.postgresql.org
  Subject: Re: Temporarily disable not null constraints
  In-Reply-To: <20201203223436.GT24052@telsasoft.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox