public inbox for [email protected]
help / color / mirror / Atom feedFrom: Amit Langote <[email protected]>
To: Postgres General <[email protected]>
Subject: Table Rewrite During ALTER TABLE ... ADD COLUMN ... DEFAULT NULL
Date: Thu, 3 Apr 2014 12:31:51 +0900
Message-ID: <CA+HiwqE35_+z0_gFw9mp=_0MLgPfb=+QY910LG7C-sBNTvqdgg@mail.gmail.com> (raw)
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgsql-general>
Hi,
When I do the following:
ALTER TABLE table ADD COLUMN numeric(x) DEFAULT NULL;
The table is rewritten whereas notes section on the manual page for
ALTER TABLE says otherwise (which holds true for most of the cases
though).
http://www.postgresql.org/docs/devel/static/sql-altertable.html
As an example,
postgres=# create table test as select generate_series(1,1000000) as a;
SELECT 1000000
postgres=# select oid, relname, relfilenode from pg_class where
relname = 'test';
oid | relname | relfilenode
-------+---------+-------------
16709 | test | 16709
(1 row)
postgres=# alter table test add column b numeric(2) DEFAULT NULL;
ALTER TABLE
-- rewritten
postgres=# select oid, relname, relfilenode from pg_class where
relname = 'test';
oid | relname | relfilenode
-------+---------+-------------
16709 | test | 16713
(1 row)
postgres=# alter table test add column c int DEFAULT NULL;
ALTER TABLE
-- not rewritten
postgres=# select oid, relname, relfilenode from pg_class where
relname = 'test';
oid | relname | relfilenode
-------+---------+-------------
16709 | test | 16713
(1 row)
postgres=# alter table test add column d char(5) DEFAULT NULL;
ALTER TABLE
-- rewritten, again
postgres=# select oid, relname, relfilenode from pg_class where
relname = 'test';
oid | relname | relfilenode
-------+---------+-------------
16709 | test | 16717
So, when the type of the new column has type modifier like numeric(x),
char(x) etc. do, this happens.
Is this intentional and/or documented somewhere else? If not, should
it be documented?
--
Amit
--
Sent via pgsql-general mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
view thread (9+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Table Rewrite During ALTER TABLE ... ADD COLUMN ... DEFAULT NULL
In-Reply-To: <CA+HiwqE35_+z0_gFw9mp=_0MLgPfb=+QY910LG7C-sBNTvqdgg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox