Re: SET NOT NULL [NOT VALID / CONCURRENTLY]?

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Joel Jacobson <joel(at)trustly(dot)com>
Cc: Craig Ringer <craig(at)2ndquadrant(dot)com>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: SET NOT NULL [NOT VALID / CONCURRENTLY]?
Date: 2016-12-22 16:16:32
Message-ID: CA+TgmoY9jpTW-Xi3GuL6G9-GiaTgR7FASutQd-fnRqwQTx+_xw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Dec 21, 2016 at 7:55 PM, Joel Jacobson <joel(at)trustly(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2016-12-22 16:26:29 Re: Write Ahead Logging for Hash Indexes
Previous Message Pavel Stehule 2016-12-22 16:11:47 Re: patch: function xmltable