Re: ALTER TABLE ... REPLACE WITH - Mailing list pgsql-hackers

From Tom Lane
Subject Re: ALTER TABLE ... REPLACE WITH
Date
Msg-id 21252.1295558658@sss.pgh.pa.us
Whole thread Raw
In response to Re: ALTER TABLE ... REPLACE WITH  (Noah Misch <noah@leadboat.com>)
Responses Re: ALTER TABLE ... REPLACE WITH  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Noah Misch <noah@leadboat.com> writes:
> Heikki's suggestion seemed straightforward, so much so that I couldn't figure
> why nobody had done it.  That would usually mean I'm missing something.

If you're willing to substitute an incompatible table, it's not clear
why you don't just do
    begin;    drop table t;    alter table t_new rename to t;    commit;

There are some implementation issues with this: concurrent accesses are
likely to end up failing with "relation with OID nnn doesn't exist",
because backends translate the table's name to OID before acquiring
lock.  But you'd have to solve those issues anyway to make an ALTER
REPLACE WITH work as transparently as you seem to hope it would.
Unless the idea here is to also have t_new acquire t's OID, and that
is an absolute complete won't-happen if you're not enforcing a pretty
thorough level of compatibility between the two tables.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Orphaned statements issue
Next
From: Tomas Vondra
Date:
Subject: Re: estimating # of distinct values