From: | "Owen Jacobson" <ojacobson(at)osl(dot)com> |
---|---|
To: | "Maciej Piekielniak" <piechcio(at)isb(dot)com(dot)pl> |
Cc: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: alter table |
Date: | 2006-02-15 19:56:05 |
Message-ID: | 144D12D7DD4EC04F99241498BB4EEDCC2207B6@nelson.osl.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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). 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
> one field?:
>
> ex (mysql):
> ALTER TABLE proc MODIFY name varchar(64) DEFAULT '' NOT NULL;
Not under 7.4.
From | Date | Subject | |
---|---|---|---|
Next Message | Stephan Szabo | 2006-02-15 20:03:26 | Re: alter table |
Previous Message | Maciej Piekielniak | 2006-02-15 19:45:00 | Re: alter table |