pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nis Jørgensen <nis@superlativ.dk>
To: pgsql-general@postgresql.org
Subject: Re: alter table table add column
Date: Tue, 31 Jul 2007 09:56:47 +0200
Message-ID: <f8mq0h$9pg$1@sea.gmane.org> (raw)
In-Reply-To: <1185855587.28634.6.camel@localhost>
References: <1185855587.28634.6.camel@localhost>

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




view thread (8+ messages)

Message-ID: <f8mq0h$9pg$1@sea.gmane.org>
Permalink:  ../f8mq0h$9pg$1@sea.gmane.org/
Also on:    postgresql.org/message-id/f8mq0h$9pg$1@sea.gmane.org

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: nis@superlativ.dk, pgsql-general@postgresql.org
  Subject: Re: alter table table add column
  In-Reply-To: <f8mq0h$9pg$1@sea.gmane.org>

* 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