Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 860A19FB8CE for ; Tue, 31 Jul 2007 04:57:27 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 52743-03 for ; Tue, 31 Jul 2007 04:57:20 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by postgresql.org (Postfix) with ESMTP id 7453F9FB8D9 for ; Tue, 31 Jul 2007 04:57:24 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IFmbW-0002rh-2m for pgsql-general@postgresql.org; Tue, 31 Jul 2007 09:57:18 +0200 Received: from cpe.atm2-0-1261189.0x503fa7b2.bynxx8.customer.tele.dk ([80.63.167.178]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 31 Jul 2007 09:57:18 +0200 Received: from nis by cpe.atm2-0-1261189.0x503fa7b2.bynxx8.customer.tele.dk with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 31 Jul 2007 09:57:18 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-general@postgresql.org From: =?ISO-8859-1?Q?Nis_J=F8rgensen?= Subject: Re: alter table table add column Date: Tue, 31 Jul 2007 09:56:47 +0200 Lines: 27 Message-ID: References: <1185855587.28634.6.camel@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: cpe.atm2-0-1261189.0x503fa7b2.bynxx8.customer.tele.dk User-Agent: Thunderbird 1.5.0.12 (Windows/20070509) In-Reply-To: <1185855587.28634.6.camel@localhost> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/1197 X-Sequence-Number: 117798 Ronald Rojas skrev: > 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. Not tested. ALTER TABLE foo ADD COLUMN age integer ALTER TABLE foo ADD COLUMN address2 character varying; UPDATE TABLE foo SET address2=address; ALTER TABLE foo DROP COLUMN address; ALTER TABLE foo RENAME COLUMN address2 TO address; Nis