Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 1A6429FBCC4 for ; Tue, 29 May 2007 17:42:06 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 16960-04 for ; Tue, 29 May 2007 17:41:58 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from p02c11o144.mxlogic.net (p02c11o144.mxlogic.net [208.65.144.77]) by postgresql.org (Postfix) with ESMTP id 270E19FB7DB for ; Tue, 29 May 2007 17:42:01 -0300 (ADT) Received: from unknown [208.65.151.10] (EHLO mxlhq-exch01.corp.mxlogic.com) by p02c11o144.mxlogic.net (mxl_mta-5.0.0-2) with ESMTP id 8109c564.2106477488.4191.00-017.p02c11o144.mxlogic.net (envelope-from ); Tue, 29 May 2007 14:42:00 -0600 (MDT) Received: from 10.30.1.68 ([10.30.1.68]) by mxlhq-exch01.corp.mxlogic.com ([10.30.0.246]) via Exchange Front-End Server webmail.mxlogic.com ([10.30.0.241]) with Microsoft Exchange Server HTTP-DAV ; Tue, 29 May 2007 20:41:58 +0000 Received: from MXLRMT-208 by webmail.mxlogic.com; 29 May 2007 14:42:13 -0600 Subject: ALTER TABLE - ALTER COLUMN question From: Keaton Adams Reply-To: kadams@mxlogic.com To: pgsql-admin@postgresql.org Content-Type: multipart/alternative; boundary="=-sDiNUDmTbDNEIVJdZPk0" Organization: MX Logic, Inc. Date: Tue, 29 May 2007 14:42:13 -0600 Message-Id: <1180471333.19986.13.camel@MXLRMT-208.corp.mxlogic.com> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 X-Spam: [F=0.0100000000; S=0.010(2007050201); SS=0.500] X-MAIL-FROM: X-SOURCE-IP: [208.65.151.10] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.803 tagged_above=0 required=5 tests=AWL=-0.647, BAYES_50=0.001, DNS_FROM_RFC_WHOIS=1.447, HTML_MESSAGE=0.001, UNPARSEABLE_RELAY=0.001, UPPERCASE_25_50=0 X-Spam-Level: X-Archive-Number: 200705/307 X-Sequence-Number: 25627 --=-sDiNUDmTbDNEIVJdZPk0 Content-Type: text/plain Content-Transfer-Encoding: 7bit When I issue an alter table ..... alter column command, the table contents are copied from the old structure to the new, correct? So I need 2x the table space available so the old and new tables can exist at the same time? PostgreSQL doesn't use an in-place alter-table for these types of changes, correct? In this example the created and msg_datetime columns are currently defined as TIMESTAMP WITHOUT TIME ZONE and no default. If the alter table for these changes is not in-place then I would want to run it as a single alter with all of the changes, such as this, instead of individual alters for each change, correct? (Because each individual alter would require another table copy?) ALTER TABLE my_table ALTER COLUMN created TYPE TIMESTAMP WITH TIME ZONE, ALTER COLUMN created SET DEFAULT ('now'::text)::TIMESTAMP(6) WITH TIME ZONE, ALTER COLUMN msg_datetime TYPE TIMESTAMP WITH TIME ZONE, ALTER COLUMN msg_datetime SET DEFAULT ('now'::text)::TIMESTAMP(6) WITH TIME ZONE; Thanks, Keaton --=-sDiNUDmTbDNEIVJdZPk0 Content-Type: text/html; charset=utf-8 When I issue an alter table ..... alter column command, the table contents are copied from the old structure to the new, correct?  So I need 2x the table space available so the old and new tables can exist at the same time?  PostgreSQL doesn't use an in-place alter-table for these types of changes, correct? 

In this example the created and msg_datetime columns are currently defined as TIMESTAMP WITHOUT TIME ZONE and no default.  If the alter table for these changes is not in-place then I would want to run it as a single alter with all of the changes, such as this, instead of individual alters for each change, correct?  (Because each individual alter would require another table copy?)

ALTER TABLE my_table ALTER COLUMN created TYPE TIMESTAMP WITH TIME ZONE,
  ALTER COLUMN created SET DEFAULT   ('now'::text)::TIMESTAMP(6) WITH TIME ZONE,
  ALTER COLUMN msg_datetime TYPE TIMESTAMP WITH TIME ZONE,
  ALTER COLUMN msg_datetime SET DEFAULT ('now'::text)::TIMESTAMP(6) WITH TIME ZONE;

Thanks,

Keaton



--=-sDiNUDmTbDNEIVJdZPk0--