Re: [HACKERS] SET NOT NULL [NOT VALID / CONCURRENTLY]? - Mailing list pgsql-hackers

From Robert Haas
Subject Re: [HACKERS] SET NOT NULL [NOT VALID / CONCURRENTLY]?
Date
Msg-id CA+TgmoY9jpTW-Xi3GuL6G9-GiaTgR7FASutQd-fnRqwQTx+_xw@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] SET NOT NULL [NOT VALID / CONCURRENTLY]?  (Joel Jacobson <joel@trustly.com>)
List pgsql-hackers
On Wed, Dec 21, 2016 at 7:55 PM, Joel Jacobson <joel@trustly.com> wrote:
Attached is the function SET_NOT_NULL(_Schema name, _Table name, _Column name) which does the following:

1. LOCK TABLE %I.%I IN ACCESS EXCLUSIVE MODE
just like the normal DDL commands would do

2. SELECT EXISTS (SELECT 1 FROM %I.%I WHERE %I IS NULL)
which is fast if there is an index on the column

3. UPDATE pg_catalog.pg_attribute SET attnotnull = TRUE
    WHERE attrelid = %L::oid
    AND   attname  = %L

Pragmatically, would this be a safe approach?

Hmm, I don't see a problem with it.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: [HACKERS] patch: function xmltable
Next
From: Robert Haas
Date:
Subject: Re: [HACKERS] Write Ahead Logging for Hash Indexes