Adding a NOT NULL column?

From: Philip Molter <philip(at)datafoundry(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Adding a NOT NULL column?
Date: 2001-06-26 16:37:59
Message-ID: 20010626113759.D12723@datafoundry.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

So I can add a column like:

ALTER TABLE t ADD c SMALLINT

and I can then set it's default value like:

ALTER TABLE t ALTER c SET DEFAULT 0

but how do set that new column to be NOT NULL? The postgres docs say
do something like:

ALTER TABLE t ADD (table constraint definition)

so I would do that like:

ALTER TABLE ADD c NOT NULL
ALTER TABLE ADD CONSTRAINT c NOT NULL

each time it fails on the 'NOT'. How do I add that constraint?

* Philip Molter
* DataFoundry.net
* http://www.datafoundry.net/
* philip(at)datafoundry(dot)net

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Åkerud 2001-06-26 16:40:57 Re: Why is NULL not indexable?
Previous Message Herbert.Liechti 2001-06-26 16:34:28 Re: Large objects in web applications