Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 949A29FB9A0 for ; Tue, 31 Jul 2007 03:25:59 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 75309-06 for ; Tue, 31 Jul 2007 03:25:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from cerberus.lfix.co.uk (lfix.demon.co.uk [80.177.205.209]) by postgresql.org (Postfix) with ESMTP id 974DE9FB98F for ; Tue, 31 Jul 2007 03:25:56 -0300 (ADT) Received: from [192.168.8.1] by cerberus.lfix.co.uk with esmtp (Exim 4.63) (envelope-from ) id 1IFlB3-00055N-Hq for pgsql-novice@postgresql.org; Tue, 31 Jul 2007 07:25:53 +0100 Subject: Re: alter table table add column From: Oliver Elphick To: pgsql-novice In-Reply-To: <1185855587.28634.6.camel@localhost> References: <1185855587.28634.6.camel@localhost> Content-Type: text/plain Organization: LFIX Date: Tue, 31 Jul 2007 07:25:53 +0100 Message-Id: <1185863153.10580.92.camel@linda.lfix.co.uk> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-LFIX-MailScanner: Found to be clean X-LFIX-MailScanner-From: olly@lfix.co.uk X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.232 tagged_above=0 required=5 tests=AWL=0.231, BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200707/110 X-Sequence-Number: 19195 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.