Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id B1DEC9FB31C for ; Wed, 4 Oct 2006 11:23:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 19629-05 for ; Wed, 4 Oct 2006 14:23:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from myemma.com (db1.e2ma.net [66.179.147.163]) by postgresql.org (Postfix) with ESMTP id 7C4AB9FB329 for ; Wed, 4 Oct 2006 11:23:38 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by myemma.com (Postfix) with ESMTP id 8955423CCA; Wed, 4 Oct 2006 09:23:36 -0500 (CDT) Received: from myemma.com ([127.0.0.1]) by localhost (velma [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 22556-03; Wed, 4 Oct 2006 09:23:36 -0500 (CDT) Received: from [10.0.23.55] (unknown [209.149.59.218]) by myemma.com (Postfix) with ESMTP id 048B723CD0; Wed, 4 Oct 2006 09:23:35 -0500 (CDT) Message-ID: <4523C3E2.4010300@myemma.com> Date: Wed, 04 Oct 2006 09:23:30 -0500 From: Erik Jones User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 To: Markus Schaber Cc: pgsql-sql@postgresql.org Subject: Re: i have table References: <45237D6E.1030601@logix-tt.com> In-Reply-To: <45237D6E.1030601@logix-tt.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at myemma.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.133 tagged_above=0 required=5 tests=FORGED_RCVD_HELO, SPF_HELO_PASS, SPF_PASS X-Spam-Level: X-Archive-Number: 200610/38 X-Sequence-Number: 26427 There is one non-SQL related reason that I like to be able to order columns, at least the way they are displayed whenever the table is described: human comprehension. For example, I like to group all keys in a table before data, that includes primary as well as foreign keys. So, say I'm building on to an existing application and I need to do an ALTER TABLE on an existing table to add a foreign key to an existing table. I'd like that key to be listed with the other keys, but presently that's not possible in a simple way and, to be honest, I usually just go without as the process you've described below is too prone to user (human) error when dealing with live, sensitive data for me to want to mess with it. Markus Schaber wrote: > 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 > > > -- erik jones software development emma(r)