Re: Bug in 7.2.1? -- ERROR: Adding columns with defaults is not implemented.

From: "Gregory Wood" <gregw(at)com-stock(dot)com>
To: <terry(at)greatgulfhomes(dot)com>
Cc: "PostgreSQL-General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Bug in 7.2.1? -- ERROR: Adding columns with defaults is not implemented.
Date: 2002-07-09 19:49:41
Message-ID: 073e01c22782$82d9d1a0$7889ffcc@comstock.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


----- Original Message -----
From: <terry(at)greatgulfhomes(dot)com>
To: "'ad wolf'" <adwolf1(at)yahoo(dot)com>; <pgsql-general(at)postgresql(dot)org>
Sent: Monday, July 08, 2002 12:10 PM
Subject: Re: [GENERAL] Bug in 7.2.1? -- ERROR: Adding columns with defaults
is not implemented.

> To implement the NOT NULL you either have to drop and recreate the table
> (which is what I do) or manually insert the appropriate trigger (Ugh).

Or update the system table:

UPDATE pg_attribute SET attnotnull=True WHERE attrelid=(SELECT oid FROM
pg_class WHERE relname='tablename') AND attname='fieldname'

Where "tablename" is the name of the table to update and "fieldname" is the
name of the NOT NULL field.

> What I do is add the column without the NOT NULL or default,
> then use the ALTER TABLE to set the column default,
> then use pg_dump -t tablename databasename > table_backup
> then vi table_backup and change the NULL to NOT NULL for the column
> then drop the table
> then reload the table with the NOT NULL constraint with:
> psql -e database < table_backup

Ugh, I find the system table UPDATE to be much easier to swallow :)

Greg

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Philip Hallstrom 2002-07-09 20:01:46 Re: I am being interviewed by OReilly
Previous Message Marc G. Fournier 2002-07-09 19:30:34 Re: I am being interviewed by OReilly