Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WVYO6-0003Ar-6a for pgsql-general@arkaria.postgresql.org; Thu, 03 Apr 2014 03:32:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WVYO5-0000x7-N6 for pgsql-general@arkaria.postgresql.org; Thu, 03 Apr 2014 03:32:21 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WVYO4-0000wy-8N for pgsql-general@postgresql.org; Thu, 03 Apr 2014 03:32:20 +0000 Received: from mail-lb0-x235.google.com ([2a00:1450:4010:c04::235]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WVYNx-0001BD-60 for pgsql-general@postgresql.org; Thu, 03 Apr 2014 03:32:19 +0000 Received: by mail-lb0-f181.google.com with SMTP id c11so872795lbj.12 for ; Wed, 02 Apr 2014 20:32:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=ZKfHIeJ92NLXoJS5A0HK0OCDsFZAE3ce4yzPFEEfUsI=; b=eM9r1W6EUrnCkA6AHUazY+h4VYnTMcg2DvOvDtnCk40kQgVyoMD4iMSTAuOGIxvsDd 8HaY1CteQuK2rHtYWdPvT8fP0DFWG40QfVN1ZsT8yeF6+BEIhzgzwv+PvXEyRvWQHsTR bXmDfsfwkJagmzQKNtIgJZWrgysYwpX5Bnb8Vel7c7BrEkOes7tNTM4zA85yfUgBUKrp NQXWrzuocfIiHIS6v0SBzXgzP2w6ZaQpMDE/2Z/N1BJqcJKVGRPa7uI7gxf4se5FvPH4 5E+olXIII0Xs5ocK2lO7HBcLoU7jNpOCRYUJmmKy3RjaXozoLjXPPJlaZzvKesArvr7l nAKg== X-Received: by 10.152.22.37 with SMTP id a5mr2666332laf.4.1396495931976; Wed, 02 Apr 2014 20:32:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.163.232 with HTTP; Wed, 2 Apr 2014 20:31:51 -0700 (PDT) From: Amit Langote Date: Thu, 3 Apr 2014 12:31:51 +0900 Message-ID: Subject: Table Rewrite During ALTER TABLE ... ADD COLUMN ... DEFAULT NULL To: Postgres General Content-Type: text/plain; charset=UTF-8 X-Pg-Spam-Score: -1.8 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org 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 (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general