Skip site navigation (1) Skip section navigation (2)

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

From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
To: Jason Cernansky <jason(at)iradix(dot)com>
Cc: PgSQL Novice ML <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Altering a table in Postgres to add a NOT NULL constraint
Date: 2002-05-27 00:35:40
Message-ID: 1022459741.10220.328.camel@rebel (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
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(dot)l(dot)johnson(at)cox(dot)net     |
| Jefferson, LA  USA |
|                                                         |
| "I have created a government of whirled peas..."        |
|   Maharishi Mahesh Yogi, 12-May-2002,                   |
!   CNN, Larry King Live                                  |

pgsql-novice by date

Next:From: Adam EricksonDate: 2002-05-27 04:43:50
Subject: Possible use of a subselect?
Previous:From: Volker RoehlDate: 2002-05-26 08:45:46
Subject: german decimal / locale

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group