X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 31C6E476323 for ; Wed, 26 Mar 2003 09:41:01 -0500 (EST) Received: from localhost.localdomain (unknown [65.217.53.66]) by postgresql.org (Postfix) with ESMTP id 1F4A9474E44 for ; Wed, 26 Mar 2003 09:40:28 -0500 (EST) Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100]) by localhost.localdomain (8.12.5/8.12.5) with ESMTP id h2QFF56P011170; Wed, 26 Mar 2003 10:15:07 -0500 Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [192.168.3.55]) by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id h2QEdtp18803; Wed, 26 Mar 2003 09:39:56 -0500 Received: from camel.mmrd.com ([172.25.5.213]) by gnvex001.mmrd.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id F3HTKYBX; Wed, 26 Mar 2003 09:39:55 -0500 Subject: Re: About changing type af a column From: Robert Treat To: Victor Yegorov Cc: Marc Soler , pgsql-admin@postgresql.org In-Reply-To: <20030326095606.GH1556@pirmabanka.lv> References: <20030326095606.GH1556@pirmabanka.lv> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 26 Mar 2003 09:39:55 -0500 Message-Id: <1048689595.13798.583.camel@camel> Mime-Version: 1.0 X-Spam-Status: No, hits=-39.4 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, QUOTE_TWICE_1,REFERENCES,REPLY_WITH_QUOTES, USER_AGENT_XIMIAN autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/442 X-Sequence-Number: 8082 On Wed, 2003-03-26 at 04:56, Victor Yegorov wrote: > * Marc Soler [26.03.2003 11:48]: > > Hi all, > > > > I need to change a column length. > > > > >From varchar(150) to varchar(250). > > > > It's easy to change with an ALTER command? Or I need to create a new > column, > > copy all data from the old column to the new one, then drop the old > and > > rename the new. > > > > If only exists the second solutions, the new column it will be created > last > > one of the columns, then I must change all INSERT and UPDATE commands > in my > > application. > > How order of fields in the table can affect UPDATE statements? > > About INSERTs - it's a good thing to specify all fields being inserted > just > to prevent 'inconveniences' like you've mentioned. > And actually relational theory states that column orders in tables is irrelevant, so it's really a good idea to make sure you keep from falling into this trap. This means referencing result set array by field name rather than by number (ie. $arr[2] - which implies field position) > > It's possible to create a column in a given position in the columns > > structure of a table?. > > Yes. create a new table with same design except for the field you'd like > to > change, than copy all data into new table, drop old one and rename new > one. > funny part is I just answered this question on the -sql list yesterday, so I happen to have the link handy to my archived post from several months back that also answers this same question; check it out: http://fts.postgresql.org/db/mw/msg.html?mid=1071582 Robert Treat