Thread: Re: Altering a table in Postgres to add a NOT NULL constraint

Re: Altering a table in Postgres to add a NOT NULL constraint

From
Ron Johnson
Date:
Hi, Jason.

On Wed, 2002-05-22 at 20:54, Jason Cernansky wrote:
> The following statement should allow you to add a not null constraint to
> a table:
>
> ALTER TABLE tablename ADD CONSTRAINT notnullchk CHECK (columnname IS NOT
> NULL);

Thanks for showing me how to prevent NULLs.  Unfortunately,
that command is a column-level CHECK constraint, not a NOT
NULL constraint needed by ALTER TABLE ... PRIMARY KEY.

How do I know?  I tried it...

So, I now have to reload the table...

--
+---------------------------------------------------------+
| Ron Johnson, Jr.        Home: ron.l.johnson@cox.net     |
| Jefferson, LA  USA      http://ronandheather.dhs.org:81 |
|                                                         |
| "I have created a government of whirled peas..."        |
|   Maharishi Mahesh Yogi, 12-May-2002,                   |
!   CNN, Larry King Live                                  |
+---------------------------------------------------------+