Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id A0B7D6507B8 for ; Fri, 11 Jul 2008 05:04:47 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 20865-04-4 for ; Fri, 11 Jul 2008 05:04:28 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx.inode.at (mx20.lb01.inode.at [62.99.145.22]) by postgresql.org (Postfix) with ESMTP id A7EFB65032F for ; Fri, 11 Jul 2008 05:01:16 -0300 (ADT) Received: from [85.124.56.44] (port=2065 helo=[10.192.17.33]) by smartmx-20.inode.at with esmtp (Exim 4.50) id 1KHDZ2-0007hp-RR; Fri, 11 Jul 2008 10:01:13 +0200 Message-ID: <48771344.3020305@sime.com> Date: Fri, 11 Jul 2008 10:01:08 +0200 From: Mario Weilguni User-Agent: Thunderbird 2.0.0.14 (X11/20080505) MIME-Version: 1.0 To: Ow Mun Heng CC: Alvaro Herrera , Pgsql performance Subject: Re: Altering a column type - Most efficient way References: <1215676380.15319.2.camel@neuromancer.home.net> <4875C9FA.7020101@sime.com> <1215682481.15319.14.camel@neuromancer.home.net> <20080710135756.GD3757@alvh.no-ip.org> <1215742620.853.10.camel@neuromancer.home.net> In-Reply-To: <1215742620.853.10.camel@neuromancer.home.net> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200807/96 X-Sequence-Number: 30696 Ow Mun Heng schrieb: > On Thu, 2008-07-10 at 09:57 -0400, Alvaro Herrera wrote: > >> Ow Mun Heng wrote: >> >> >>> This is what I see on the table >>> >>> NEW attypmod = -1 >>> OLD attypmod = 8 >>> >> 8 means varchar(4) which is what you said you had (4+4) >> -1 means unlimited size. >> >> > > This is cool. > > If it were this simple a change, I'm not certain why (I believe) PG is > checking each and every row to see if it will fit into the new column > definition/type. > > Thus, I'm still a bit hesitant to do the change, although it is > definitely a very enticing thing to do. ( I presume also that this > change will be instantaneous and does not need to check on each and > every row of the table?) > > Thanks./ > > It should be safe, because the length limit is checked at insert/update time, and internally, a varchar(20) is treated as something like this: foo varchar(1000000000) check (length(foo) <= 20) The change is done without re-checking all rows, and will not fail IF the new size is longer than the old size.