[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-general
Subject:    Re: [GENERAL] alter table table add column
From:       Nis_Jørgensen <nis () superlativ ! dk>
Date:       2007-07-31 7:56:47
Message-ID: f8mq0h$9pg$1 () sea ! gmane ! org
[Download RAW message or body]

Ronald Rojas skrev:
> Hi,
> 
> Anybody knows how to add column with reference to BEFORE or AFTER any
> given column? Let say here's my table structure:
> 
>   Column  |       Type        | Modifiers 
> ----------+-------------------+-----------
>  surname  | character varying | 
>  lastname | character varying | 
>  address   | character varying |
> 
> And, I want to add the field name age with type integer after lastname
> OR before the address field. How to I do that?
> 
> I would really appreciate your response.

Not tested.

ALTER TABLE foo ADD COLUMN age integer
ALTER TABLE foo ADD COLUMN address2 character varying;
UPDATE TABLE foo SET address2=address;
ALTER TABLE foo DROP COLUMN address;
ALTER TABLE foo RENAME COLUMN address2 TO address;


Nis


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@postgresql.org so that your
       message can get through to the mailing list cleanly
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic