Re: Bug in 7.2.1? -- ERROR: Adding columns with defaults

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: ad wolf <adwolf1(at)yahoo(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Bug in 7.2.1? -- ERROR: Adding columns with defaults
Date: 2002-07-08 17:04:25
Message-ID: 20020708095958.L27784-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> Using pg 7.1.2, I can enter the following statement successfully:
>
> # alter table manufacturer add column dummy integer not null default
> 1;
>
> However, under 7.2.1, the same statement gets me --
>
> ERROR: Adding columns with defaults is not implemented.
> Add the column, then use ALTER TABLE SET DEFAULT.
>
> My question is two-fold -- first, is this new behavior a feature, or a
> bug?

IIRC, the column's default was lost in past versions so the statement
never really worked.

> I'd like to stick with 7.2.1, but this new behavior is making it
> difficult for me. I can't simply drop & recreate all my tables just
> to add a column!

Do it in two or three statements:
alter table manufacturer add column dummy integer;
alter table manufacturer alter column dummy set default 1;
-- if you want past rows to have 1 rather than null
update manufacturer set dummy=1;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2002-07-08 17:07:11 Re: Null in the where-clause
Previous Message Andrew Sullivan 2002-07-08 17:02:04 Re: Bug in 7.2.1? -- ERROR: Adding columns with defaults is not implemented.