X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DC5689DCA17 for ; Wed, 15 Feb 2006 16:09:47 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 08330-02 for ; Wed, 15 Feb 2006 16:09:48 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id DCD799DCA09 for ; Wed, 15 Feb 2006 16:09:45 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 61B4035313; Wed, 15 Feb 2006 12:03:26 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 5CA5735304; Wed, 15 Feb 2006 12:03:26 -0800 (PST) Date: Wed, 15 Feb 2006 12:03:26 -0800 (PST) From: Stephan Szabo To: Owen Jacobson Cc: Maciej Piekielniak , pgsql-sql@postgresql.org Subject: Re: alter table In-Reply-To: <144D12D7DD4EC04F99241498BB4EEDCC2207B6@nelson.osl.com> Message-ID: <20060215120109.S99569@megazone.bigpanda.com> References: <144D12D7DD4EC04F99241498BB4EEDCC2207B6@nelson.osl.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.136 required=5 tests=[AWL=0.136, UPPERCASE_25_50=0] X-Spam-Score: 0.136 X-Spam-Level: X-Archive-Number: 200602/184 X-Sequence-Number: 24194 On Wed, 15 Feb 2006, Owen Jacobson wrote: > Maciej Piekielniak wrote: > > > > Wednesday, February 15, 2006, 8:31:17 PM, you wrote: > > OJ> Note that prior to 8.0 PostgreSQL does not support > > multiple ALTER actions in a single query. To get an > > equivalent effect, wrap separate ALTER TABLE queries in a transaction: > > > > OJ> BEGIN; > > OJ> alter table xyz alter column id set default nextval('xyz_seq'); > > OJ> alter table xyz alter column foo set default ''; > > OJ> COMMIT; > > OJ> Also, are you sure you want '' as a column default, and > > not ALTER COLUMN foo DROP DEFAULT? > > OJ> -Owen > > > > OK. THX. Second question: > > > > First, maybe set many fields with the same action - ex. set default? > > > > Ex. on mysql > > > > ALTER TABLE proc MODIFY name char(64) DEFAULT '' NOT NULL, > > MODIFY specific_name char(64) DEFAULT '' NOT NULL, > > MODIFY sql_data_access > > enum('CONTAINS_SQL', > > 'NO_SQL', > > 'READS_SQL_DATA', > > 'MODIFIES_SQL_DATA' > > ) DEFAULT 'CONTAINS_SQL' NOT NULL.... > > Under PostgreSQL 7.4 you'd need to do those as three separate ALTER TABLE statements: > > BEGIN; > ALTER TABLE proc ALTER name DEFAULT '' NOT NULL; > ALTER TABLE proc ALTER specific_name DEFAULT '' NOT NULL; > ... and so on ... > COMMIT; > > Note that ALTER TABLE under postgresql cannot change a column's type > (including precision or length). Not in 7.4, but I believe 8.1 allows that (ALTER TABLE ALTER COLUMN TYPE with semi-optional USING)