pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Markus Schaber <schabi@logix-tt.com>
To: pgsql-sql@postgresql.org
Subject: Re: i have  table
Date: Wed, 04 Oct 2006 11:22:54 +0200
Message-ID: <45237D6E.1030601@logix-tt.com> (raw)
In-Reply-To: <A70AE049E81A6A40879D5DC0AC8C38C9073DCD8F@venus.infics.com>
References: <A70AE049E81A6A40879D5DC0AC8C38C9073DCD8F@venus.infics.com>

Hi, Penchalaiah,

Penchalaiah P. wrote:

> now I want to add one more field in this table.. but that field has to
> come next to cda_no.. I mean as a 3^rd field.. If I am adding that field
> it is coming last field …

In SQL, field order in the table is not given by design.

A "SELECT * FROM table" might even give you the columns alphabetically
ordered, or in a different random order each time in a different server
implementation.

If you need the colums in a specific order, use "SELECT foo, bar, baz
FROM table" or create a View.

All relevant SQL constructs (SELECT, INSERT, UPDATE, COPY, etc.) let you
specify the columns explicitly to guarantee a given order.

> may I know how it is possible to that table…

If you _really_ want to do that despite what I wrote above, you have
several possibilities:

- COPY the table to some file, drop the table, recreate the table with
  the desired new column order, and then COPY the table back using an
  explicitly specified, correct row order.

- use CREATE TABLE ... AS SELECT to select the data into a new table,
  drop the old table, rename the new one to the old one.

In both cases, you've to recreate all missing indices, foreing key
constraints etc.


HTH,
Markus


-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in Europe! www.ffii.org
www.nosoftwarepatents.org




view thread (19+ messages)  latest in thread

Message-ID: <45237D6E.1030601@logix-tt.com>
Permalink:  ../45237D6E.1030601@logix-tt.com/
Also on:    postgresql.org/message-id/45237D6E.1030601@logix-tt.com

 · 

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: schabi@logix-tt.com
  Subject: Re: i have  table
  In-Reply-To: <45237D6E.1030601@logix-tt.com>

* 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