Re: Happy column adding

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Hiroshi Inoue <Inoue(at)tpf(dot)co(dot)jp>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Happy column adding
Date: 2000-01-26 18:35:28
Message-ID: Pine.LNX.4.21.0001261539580.416-100000@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2000-01-25, Tom Lane mentioned:

> > IIRC,there were some reason that default for new column had been rejected.
>
> Well, yeah: wouldn't you expect that "ADD COLUMN x DEFAULT 42" would
> cause every row currently existing in the table to acquire x = 42,

Sure. But whatever happened to
pg_exec_query_dest("update <tablename> set <newcolname> = <default>")

This is what users would have to execute anyway, right?

Look at this:

=> create table test1 (a text);
=> insert into test1 values ('blah');
=> insert into test1 values ('blah');
=> insert into test1 values ('blah');
=> alter table test1 add column b serial;
=> select * from test1;
a | b
------+---
blah | 1
blah | 2
blah | 3
(3 rows)

Not good?

> rather than x = NULL? In fact that would *have* to happen to allow
> constraints to be added; consider ADD COLUMN x DEFAULT 42 NOT NULL.

Or how about (continuing the above):

=> alter table test1 add column c int not null;
ERROR: ALTER TABLE: adding NOT NULL attribute to non-empty table requires
a non-NULL default value

> The only way to make that happen is for ADD COLUMN to switch over to
> an implementation that rewrites all the tuples. Which I think is the
> right way to go ... but per this discussion, it's not a trivial fix.

So what's the above doing? Seriously, is there silently creeping heap
corruption I'm not seeing?

--
Peter Eisentraut Sernanders väg 10:115
peter_e(at)gmx(dot)net 75262 Uppsala
http://yi.org/peter-e/ Sweden

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2000-01-26 18:40:54 Re: [HACKERS] DISTINCT ON: speak now or forever hold your peace
Previous Message Peter Eisentraut 2000-01-26 18:35:14 Re: [HACKERS] Inheritance, referential integrity and other constraints