Different results when specifying DEFAULT values through ALTER TABLE

From: "Thusitha Kodikara" <tkodikara(at)openworld(dot)org>
To: <pgsql-admin(at)postgresql(dot)org>
Subject: Different results when specifying DEFAULT values through ALTER TABLE
Date: 2006-04-19 06:58:27
Message-ID: 200604190653.k3J6rHVo000891@rly18b.srv.mailcontrol.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi,

I observed the following on PostgreSQL 8.1.3 (on Windows 2000).

(1) alter table invoice add column active boolean default true;

This will add a new column "active" with a default clause as "true" and also sets the value "true" to all existing rows of the table.

BUT

(2) ALTER TABLE invoice ADD COLUMN active boolean;
ALTER TABLE invoice ALTER COLUMN active SET DEFAULT true;

Will result in only adding the column "active" with default clause as "true". It will NOT set the value "true" for existing rows.

Is there a particular reason for this difference in behaviour? (Or am I missing something in the syntax?)

Thanks and regards,

-Thusitha Kodikara
--

CONFIDENTIALITY NOTICE The information contained in this message is
confidential, intended only for the use of the individual or the entity
named as recipient. If the reader of this message is not that recipient,
you are notified that any dissemination, distribution or copy of this
message is strictly prohibited. If you have received this message in
error, please immediately notify us by telephone on the number above.
Your co-operation is appreciated.

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message koji osada 2006-04-19 07:49:11 Migration from oracle
Previous Message Tom Lane 2006-04-19 05:29:13 Re: PGOPTS