Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 64B3317B105B for ; Fri, 11 May 2012 17:00:18 -0300 (ADT) Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SSw0e-0000e6-Ir for pgsql-sql@postgresql.org; Fri, 11 May 2012 20:00:17 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SSw0Q-00029T-KC for pgsql-sql@postgresql.org; Fri, 11 May 2012 22:00:02 +0200 Received: from ppp-188-174-5-97.dynamic.mnet-online.de ([188.174.5.97]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 May 2012 22:00:02 +0200 Received: from spam_eater by ppp-188-174-5-97.dynamic.mnet-online.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 May 2012 22:00:02 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Thomas Kellerer Subject: Re: Finding Max Value in a Row Date: Fri, 11 May 2012 22:00:52 +0200 Lines: 22 Message-ID: References: <00ee01cd2fab$1b528b80$51f7a280$@yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: ppp-188-174-5-97.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.21) Gecko/20090302 Thunderbird/2.0.0.21 Mnenhy/0.7.5.666 In-Reply-To: X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/19 X-Sequence-Number: 36567 Carlos Mennens wrote on 11.05.2012 21:50: > On Fri, May 11, 2012 at 3:44 PM, Thomas Kellerer wrote: >> Use this: >> >> alter table users >> alter column users_id type integer using to_number(users_id, '99999'); >> >> (Adjust the '99999' to the length of the char column) > > When you wrote "Adjust the '99999' to the length of the char column, > do you mean change '99999' to '312' if my last used maximum value was > 312? So the next sequence primary key value would be '313', right? > No, the number of 9's defined the number of digits in the numbers. There must not be less 9's in the format mask than the number of digits in the highest value. The above example would create wrong values if the highest "number" was 100000 Check the manual about details on the format mask for to_number()