From: | Guillaume LELARGE <guillaume(dot)lelarge(at)gmail(dot)com> |
---|---|
To: | emilu(at)encs(dot)concordia(dot)ca |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Add column and specify the column position in a table |
Date: | 2006-05-18 05:53:04 |
Message-ID: | 446C0BC0.7050805@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Emi Lu a écrit :
> I am trying to insert one column to a specific position in a table.
>
> In mysql, I can do:
> . create table test(id varchar(3), name varchar(12));
> . alter table test add column givename varchar(12) after id;
>
>
> I am looking for similar things in postgresql to add a new column to the
> correct position in a table.
>
> Could someone hint me please.
>
There's no similar thing in PostgreSQL. You have to duplicate the table
to do it. You can do it in a transaction :
CREATE TABLE test (id varchar(3), name varchar(12));
then later :
BEGIN;
ALTER TABLE test RENAME TO oldtest;
CREATE TABLE test (id varchar(3), givename varchar(12), name varchar(12));
INSERT INTO test (id, name) SELECT id, name FROM oldtest;
DROP TABLE oldtest;
COMMIT;
Not really interesting if you have really big tables but, in fact, you
shouldn't rely on columns' order.
Regards.
--
Guillaume.
From | Date | Subject | |
---|---|---|---|
Next Message | A. Kretschmer | 2006-05-18 06:12:13 | Re: Question about SQL Control Structure(if then, for loop) |
Previous Message | Pavan Kumar | 2006-05-18 05:45:25 | error : could not access status of transaction |