From: Stewart Ben (RBAU/EQS4) * <Ben.Stewart@au.bosch.com>
To: pgsql-sql@postgresql.org
Subject: Re: changing a column's position in table, how do you do that
Date: Wed, 28 Sep 2005 10:25:04 +1000
Message-ID: <E253BDD7F008244585AEE87AF8F0224F116C7A74@cl-mail01.au.bosch.com> (raw)
Ferindo,
> Is there a way to change the position attribute of a column
> in a table?
AFAIK, there's no way to change this easily. The best way to do it would
be as follows:
BEGIN WORK;
LOCK TABLE mytable IN ACCESS EXCLUSIVE MODE;
ALTER TABLE mytable ADD COLUMN col_to_move_2 coltype;
UPDATE mytable SET col_to_move_2 = col_to_move;
ALTER TABLE mytable DROP COLUMN col_to_move;
ALTER TABLE mytable RENAME col_to_move_2 TO col_to_move;
COMMIT WORK;
Best regards,
Ben Stewart
--
Robert Bosch (Australia) Pty. Ltd.
Engineering Quality Services, Student Software Engineer (RBAU/EQS4)
Locked Bag 66 - Clayton South, VIC 3169 - AUSTRALIA
mailto:ben.stewart@au.bosch.com
http://www.bosch.com.au/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: Ben.Stewart@au.bosch.com
Subject: Re: changing a column's position in table, how do you do that
In-Reply-To: <E253BDD7F008244585AEE87AF8F0224F116C7A74@cl-mail01.au.bosch.com>
References: <E253BDD7F008244585AEE87AF8F0224F116C7A74@cl-mail01.au.bosch.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox