Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 4BAEE17B105B for ; Fri, 11 May 2012 16:43:32 -0300 (ADT) Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SSvkR-0000Q4-7p for pgsql-sql@postgresql.org; Fri, 11 May 2012 19:43:31 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SSvkE-0000me-Ar for pgsql-sql@postgresql.org; Fri, 11 May 2012 21:43:18 +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 21:43:18 +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 21:43:18 +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 21:44:03 +0200 Lines: 35 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/15 X-Sequence-Number: 36563 Carlos Mennens wrote on 11.05.2012 21:30: > Thanks for all the help thus far everyone! I sadly didn't > create/design the table and would love to create a SEQUENCE on that > particular field but not sure how unless I DROP the table and create > from scratch. > > Currently the data TYPE on the primary key field (users_id) is CHAR > and I have no idea why...it should be NUMERIC or SERIAL but it's not > so my question is if I want to ALTER the column and create a sequence, > would I simply do: > > ALTER TABLE users > ALTER COLUMN users_id TYPE serial > ; > > Obviously if any of the data stored in users_id is actual CHAR, I'm > guessing the database would reject that request to change type as the > existing data would match. However the data type is CHAR but the field > values are all numeric from 1000000010 - 1000000301 so I'm hoping that > would work for SERIAL which is just INTEGER, right? 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) Then create and "assign" the new sequence as I have shown in my other post.