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 6FBBB9DC85A for ; Wed, 15 Feb 2006 15:56:11 -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 05047-07 for ; Wed, 15 Feb 2006 15:56:11 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from nelson.osl.com (216-21-133-120.ip.van.radiant.net [216.21.133.120]) by postgresql.org (Postfix) with ESMTP id 2C8489DC843 for ; Wed, 15 Feb 2006 15:56:08 -0400 (AST) Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Subject: Re: alter table Date: Wed, 15 Feb 2006 11:56:05 -0800 Message-ID: <144D12D7DD4EC04F99241498BB4EEDCC2207B6@nelson.osl.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Re[2]: [SQL] alter table Thread-Index: AcYyaAt9OHIs6WDiR9CGz8uCmmkQSgAADngQ From: "Owen Jacobson" To: "Maciej Piekielniak" Cc: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.111 required=5 tests=[AWL=0.111, UPPERCASE_25_50=0] X-Spam-Score: 0.111 X-Spam-Level: X-Archive-Number: 200602/181 X-Sequence-Number: 24191 Maciej Piekielniak wrote: >=20 > Wednesday, February 15, 2006, 8:31:17 PM, you wrote: > OJ> Note that prior to 8.0 PostgreSQL does not support=20 > multiple ALTER actions in a single query. To get an=20 > equivalent effect, wrap separate ALTER TABLE queries in a transaction: >=20 > 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=20 > not ALTER COLUMN foo DROP DEFAULT? > OJ> -Owen >=20 > OK. THX. Second question: >=20 > First, maybe set many fields with the same action - ex. set default? >=20 > Ex. on mysql >=20 > 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). You can fake it by renaming the = existing column, creating a new column of the appropriate type, = UPDATEing data from the old column to the new column, [setting the new = column's constraints,] and finally removing the old column, but it's a = long-winded process. > Second, can i modify more than 1 option with alter table on=20 > one field?: >=20 > ex (mysql): > ALTER TABLE proc MODIFY name varchar(64) DEFAULT '' NOT NULL; Not under 7.4.