Re: Add Column BEFORE/AFTER another column

From: Bill Moran <wmoran(at)potentialtech(dot)com>
To: Matthew <mboehm(at)voilaip(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Add Column BEFORE/AFTER another column
Date: 2007-08-24 21:11:18
Message-ID: 20070824171118.6e37a202.wmoran@potentialtech.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In response to Matthew <mboehm(at)voilaip(dot)com>:

> Hi gang,
> In MySQL it is possible to add a column before/after another column. I
> have not been able to find such syntax in the Postgres manual. Does this
> ability exist?

It does not.

> Is my only solution to create a new table with the new column, copy the
> data, delete the old table and rename the new one?

The fact that you're asking this question is a hint that you're using
unsafe coding practices that may bite you at some point. The order
of columns is not guaranteed to be the same as when you do CREATE
TABLE, it's just coincidence that they usually are.

To get your columns in a specific order, specify the column names in
that order in your SELECT statement. The SQL standard doesn't provide
for any other way to guarantee column order, and neither does Postgres.

--
Bill Moran
http://www.potentialtech.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Matthew 2007-08-24 21:18:18 Re: Add Column BEFORE/AFTER another column
Previous Message Matthew 2007-08-24 20:55:42 Add Column BEFORE/AFTER another column