Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 36F2E17B105B for ; Fri, 11 May 2012 16:44:37 -0300 (ADT) Received: from mail-pz0-f46.google.com ([209.85.210.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SSvlT-0000QM-UK for pgsql-sql@postgresql.org; Fri, 11 May 2012 19:44:36 +0000 Received: by dady13 with SMTP id y13so3489987dad.19 for ; Fri, 11 May 2012 12:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=1AoIY+HKeloxS0mFwUGv8EJFENqnDgLF+CzbkJPVVbw=; b=AT9Tqvajj2sdKw3GnwOzDJLvTV5RAmlSxd5GOFIAleNI7+DhJcbQBk3/VH5P9xUP2W TZUkLbGYcPmbn5HOZq0Mln9Tj9Mi2a9wjnuhNLu293UGiJ3vZUJDvB7TkUP5soBoVvLF k1/h1lhPQV7i70wY+AV/8UvkzQM6IMgiEvSnWKV8aAsClzh6b/VItw7JbMs5Mm3Yzg+y 2IWu6mULEn/AU5lVzxq8k1OB/ZHPDQ01g5bKLA5aoPakxcP0a4kmjm3udfbzHczgGjZz Oog7rt7jBflz54bXOV3z4w2POSYDshq9FJ2SzqAG9h5fXt3eZnE1auvlrjwf2WFrfzG2 ellg== Received: by 10.68.216.225 with SMTP id ot1mr8317093pbc.46.1336765463058; Fri, 11 May 2012 12:44:23 -0700 (PDT) Received: from [192.168.0.3] (c-24-17-164-54.hsd1.wa.comcast.net. [24.17.164.54]) by mx.google.com with ESMTPS id nv2sm13678388pbb.6.2012.05.11.12.44.22 (version=SSLv3 cipher=OTHER); Fri, 11 May 2012 12:44:22 -0700 (PDT) Message-ID: <4FAD6BFE.3090905@gmail.com> Date: Fri, 11 May 2012 12:43:58 -0700 From: Adrian Klaver User-Agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: Carlos Mennens CC: "PostgreSQL (SQL)" Subject: Re: Finding Max Value in a Row References: <00ee01cd2fab$1b528b80$51f7a280$@yahoo.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201205/16 X-Sequence-Number: 36564 On 05/11/2012 12:30 PM, Carlos Mennens wrote: > 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? > Well the question to ask is if it is declared CHAR was that done for a legitimate reason? One reason I can think of is to have leading 0s in a 'number'. Might want to double check that code downstream is not depending on CHAR behavior. -- Adrian Klaver adrian.klaver@gmail.com