pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gus Spier <gus.spier@gmail.com>
To: depesz@depesz.com
Cc: Alexander Kukushkin <cyberdemn@gmail.com>
Cc: pgsql-general mailing list <pgsql-general@postgresql.org>
Subject: Re: Is there any technical reason why "alter table .. set not null" can't use index?
Date: Fri, 10 Sep 2021 13:26:46 -0400
Message-ID: <7E44EA26-9343-444F-B01C-30944AB8C60A@gmail.com> (raw)
In-Reply-To: <20210908051453.GB20274@depesz.com>
References: <20210908051453.GB20274@depesz.com>

Would it help to create a new not null column in the target table, and then update the table by copying values from old column to the new, not null column? Of course you’d have to ignore errors, etc. but wouldn’t that perform at enough for your needs?

Sent from my iPhone

> On Sep 8, 2021, at 1:15 AM, hubert depesz lubaczewski <depesz@depesz.com> wrote:
> 
> On Wed, Sep 08, 2021 at 07:09:31AM +0200, Alexander Kukushkin wrote:
>> Hi,
>> 
>>> On Wed, 8 Sep 2021, 06:59 hubert depesz lubaczewski, <depesz@depesz.com>
>>> wrote:
>>> 
>>> Hi,
>>> we needed recently to add not null constraint on some fields, and it
>>> struck me that it took long.
>>> Obviously - pg has to check the data. But it seems that it can't use
>>> index.
>>> 
>> 
>> It can't use the index, but can use an already existing CHECK CONSTRAINT,
>> that could be created as NOT VALID and validated without holding heavy
>> locks. After adding not null you can drop the constraint.
> 
> Thanks. Forgot about these.
> 
> Best regards,
> 
> depesz
> 
> 
> 





view thread (5+ messages)  latest in thread

Message-ID: <7E44EA26-9343-444F-B01C-30944AB8C60A@gmail.com>
Permalink:  ../7E44EA26-9343-444F-B01C-30944AB8C60A@gmail.com/
Also on:    postgresql.org/message-id/7E44EA26-9343-444F-B01C-30944AB8C60A@gmail.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: gus.spier@gmail.com, depesz@depesz.com, cyberdemn@gmail.com
  Subject: Re: Is there any technical reason why "alter table .. set not null" can't use index?
  In-Reply-To: <7E44EA26-9343-444F-B01C-30944AB8C60A@gmail.com>
  References: <20210908051453.GB20274@depesz.com> <7E44EA26-9343-444F-B01C-30944AB8C60A@gmail.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