Skip site navigation (1) Skip section navigation (2)

Re: Alter Column Position

From: hodges(at)xprt(dot)net
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Alter Column Position
Date: 2003-12-10 15:18:02
Message-ID: 3FD6C8AA.11093.249423@localhost (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novice
Yes I did that and lost all the connections to my sequences.

Tom

On 10 Dec 2003 at 13:16, Nabil Sayegh wrote:

> Derrick Betts wrote:
> > I have a table with 10,000 rows.  We have an application that parses a *.csv
> > file and uploads the data to the database table.  The csv parser takes the
> > column numbers form the csv file and matches the column numbers to the field
> > positions in the DB table.
> > 
> > Now, I have to change the position of a column in the DB to match the csv
> > parser.  I have a column in position 28 that I need to move to position 7.
> > 
> > Anyone know how to do that?
> 
> You could DROP and re-CREATE the table.
> 
> CREATE TABLE tmp AS SELECT col1, col3, col2 FROM mytab;
> DROP TABLE mytab;
> ALTER TABLE tmp RENAME TO mytab;
> 
> _BUT_: You need to take care of special cases like UNIQUE & FOREIGN KEYs 
> etc., i.e. usually you need a better CREATE clause than this easy example.
> 
> 
> > Thanks,
> > Derrick
> 
> HTH
> -- 
>   e-Trolley Sayegh & John, Nabil Sayegh
>   Tel.: 0700 etrolley /// 0700 38765539
>   Fax.: +49 69 8299381-8
>   PGP : http://www.e-trolley.de
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 



In response to

pgsql-novice by date

Next:From: Amy YoungDate: 2003-12-10 15:34:36
Subject: Re: PostgreSQL Training
Previous:From: Sai Hertz And Control SystemsDate: 2003-12-10 15:17:43
Subject: Re: [NOVICE] PostgreSQL Training

pgsql-general by date

Next:From: Keith C. PerryDate: 2003-12-10 15:27:12
Subject: Re: Users and session ids
Previous:From: Sai Hertz And Control SystemsDate: 2003-12-10 15:17:43
Subject: Re: [NOVICE] PostgreSQL Training

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group