Re: Finding Max Value in a Row

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Finding Max Value in a Row
Date: 2012-05-11 20:00:52
Message-ID: jojr3q$uof$1@dough.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Carlos Mennens wrote on 11.05.2012 21:50:
> On Fri, May 11, 2012 at 3:44 PM, Thomas Kellerer<spam_eater(at)gmx(dot)net> 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()

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Kellerer 2012-05-11 20:05:24 Re: Finding Max Value in a Row
Previous Message Carlos Mennens 2012-05-11 19:53:59 Re: Finding Max Value in a Row