X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id D10879FB339 for ; Thu, 18 May 2006 03:04:01 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 12792-03 for ; Thu, 18 May 2006 03:03:56 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.190]) by postgresql.org (Postfix) with ESMTP id 912D29FB6AC for ; Thu, 18 May 2006 02:41:19 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id y38so69844nfb for ; Wed, 17 May 2006 22:41:17 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:organization:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding; b=jIdQdjeYouf9wOrUGb6nUP+68n4HQNA1mhljY/zBHxXDoMJT91UYn3zHn5wI9qiDmnRsvWrdl/CYbJMoOgXYRHy2sCnwBcpew+SpTFhADYIoehg71/Iw/pb9c6822cJs1SsMMdvN9TY2BDeAJJ8Ob5Xn15op5g6/YHY72rzhtcI= Received: by 10.48.48.16 with SMTP id v16mr182898nfv; Wed, 17 May 2006 22:41:17 -0700 (PDT) Received: from ?192.168.10.4? ( [83.112.76.220]) by mx.gmail.com with ESMTP id x27sm198390nfb.2006.05.17.22.41.15; Wed, 17 May 2006 22:41:17 -0700 (PDT) Message-ID: <446C0BC0.7050805@gmail.com> Date: Thu, 18 May 2006 07:53:04 +0200 From: Guillaume LELARGE Organization: traduc.org, postgresqlfr.org User-Agent: Thunderbird 1.5 (X11/20060309) MIME-Version: 1.0 To: emilu@encs.concordia.ca CC: pgsql-sql@postgresql.org Subject: Re: Add column and specify the column position in a table References: <446B9418.3080700@encs.concordia.ca> In-Reply-To: <446B9418.3080700@encs.concordia.ca> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/130 X-Sequence-Number: 25161 Emi Lu a écrit : > I am trying to insert one column to a specific position in a table. > > In mysql, I can do: > . create table test(id varchar(3), name varchar(12)); > . alter table test add column givename varchar(12) after id; > > > I am looking for similar things in postgresql to add a new column to the > correct position in a table. > > Could someone hint me please. > There's no similar thing in PostgreSQL. You have to duplicate the table to do it. You can do it in a transaction : CREATE TABLE test (id varchar(3), name varchar(12)); then later : BEGIN; ALTER TABLE test RENAME TO oldtest; CREATE TABLE test (id varchar(3), givename varchar(12), name varchar(12)); INSERT INTO test (id, name) SELECT id, name FROM oldtest; DROP TABLE oldtest; COMMIT; Not really interesting if you have really big tables but, in fact, you shouldn't rely on columns' order. Regards. -- Guillaume.