pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Elphick <olly@lfix.co.uk>
To: pgsql-novice <pgsql-novice@postgresql.org>
Subject: Re: alter table table add column
Date: Tue, 31 Jul 2007 07:25:53 +0100
Message-ID: <1185863153.10580.92.camel@linda.lfix.co.uk> (raw)
In-Reply-To: <1185855587.28634.6.camel@localhost>
References: <1185855587.28634.6.camel@localhost>

On Tue, 2007-07-31 at 12:19 +0800, Ronald Rojas wrote:
> 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.

It isn't possible.  Nor is it really necessary, since you can ask for
columns in any order in a SELECT.

If you really want to do it, you need to dump the table to a new table
with the columns in the desired order; delete the old table and rename
the new one.

Alternatively, add the new column (which will come at the end), add a
new address column and set its contents to be the same as the current
address column, finally drop the old address column.  (This will waste
space in the table.)

-- 
Oliver Elphick                                          olly@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA  92C8 39E7 280E 3631 3F0E  1EC0 5664 7A2F A543 10EA
                 ========================================
   Do you want to know God?   http://www.lfix.co.uk/knowing_god.html


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




view thread (8+ messages)  latest in thread

Message-ID: <1185863153.10580.92.camel@linda.lfix.co.uk>
Permalink:  ../1185863153.10580.92.camel@linda.lfix.co.uk/
Also on:    postgresql.org/message-id/1185863153.10580.92.camel@linda.lfix.co.uk

 · 

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: olly@lfix.co.uk, pgsql-novice@postgresql.org
  Subject: Re: alter table table add column
  In-Reply-To: <1185863153.10580.92.camel@linda.lfix.co.uk>

* 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