Skip site navigation (1) Skip section navigation (2)

Re: unimplemented functions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: chris(at)zenmgt(dot)com
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: unimplemented functions
Date: 2004-03-19 15:32:50
Message-ID: 24446.1079710370@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-admin
chris(at)zenmgt(dot)com writes:
> ERROR:  adding columns with defaults is not implemented
> HINT:  Add the column, then use ALTER TABLE SET DEFAULT.

> When will this be fixed?

Probably not very soon, as it is easily worked around, and the
spec-mandated behavior is not necessarily what you want anyway.

ALTER TABLE t ADD COLUMN c INT DEFAULT 42;

is equivalent per SQL spec to

ALTER TABLE t ADD COLUMN c INT;
ALTER TABLE t ALTER COLUMN c SET DEFAULT 42;
UPDATE t SET c = DEFAULT;

That last step is fairly expensive since it forces an update of every
row of the table.  (The ALTERs themselves only touch catalog data and
are cheap even with large tables.)  If you are intending to load the new
column with non-default values then you probably don't really want the
UPDATE step.  Without it, the new column will read as NULL until you
get around to setting it.

			regards, tom lane

In response to

pgsql-admin by date

Next:From: scott.marloweDate: 2004-03-19 15:51:46
Subject: Re: Re-Init database cluster.
Previous:From: Luz Aida Uribe VelezDate: 2004-03-19 15:25:57
Subject: Differential Backup

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group