set not null column using existing constraint

From: Marco Piovan <mpiovan(at)workwave(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: set not null column using existing constraint
Date: 2018-01-10 12:09:03
Message-ID: CAKGTZp7V9=Zuqum5fam0wBe0n1e6TVu+8MLf03Fo-y1JaVMLzw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hello,
I want to create a primary key using an existing unique index.
I have already created the index concurrently and I have already validated
a not null constraint on the same column.

Looking at the postgres documentation (
https://www.postgresql.org/docs/9.6/static/sql-altertable.html):

"If PRIMARY KEY is specified, and the index's columns are not already
marked NOT NULL, then this command will attempt to do ALTER COLUMN SET NOT
NULL against each such column. That requires a full table scan to verify
the column(s) contain no nulls. In all other cases, this is a fast
operation."

Is it possible to specify the already validated not null constraint and
avoid another scan of the table (with lock)?

Best regards

--
Marco Piovan

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Francis Santiago 2018-01-10 13:22:48 Re: pgAdmin Import/export does not show a progress dialog on mac
Previous Message Damir Colak 2018-01-09 16:57:13 pgAdmin Import/export does not show a progress dialog on mac