Re: adding not null constraint to existing table

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Alex Howansky <alex(at)wankwood(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: adding not null constraint to existing table
Date: 2001-02-02 17:44:08
Message-ID: Pine.BSF.4.21.0102020940270.21728-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Fri, 2 Feb 2001, Alex Howansky wrote:

>
> What's the simplest way to add a not null constraint to a field in an existing
> table? It doesn't seem that alter table supports it -- that I'll have to create
> a new table and copy into it. Is that correct? TIA,

You can also do something to the system catalogs as a superuser to set
attnotnull to true in pg_attribute for the particular attribute you want.

Something like:
update pg_attribute set attnotnull='t' where
pg_attribute.attrelid=pg_class.oid and pg_class.relname=<table> and
attname=<attribute>;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Anand Raman 2001-02-02 18:39:17 Re: plpgsql always returning null..
Previous Message Stephan Szabo 2001-02-02 17:39:35 Re: Re: sintax???