Re: interesting sequence

From: John Fabiani <johnf(at)jfcomputer(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: interesting sequence
Date: 2011-07-05 21:42:29
Message-ID: 201107051442.29875.johnf@jfcomputer.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tuesday, July 05, 2011 01:11:11 pm Kevin Crain wrote:
> You don't need a loop there. Assuming your order id field is of type
> varchar you can just build the first part of your string and then do a
> count to get the last part using a LIKE comparison:
>
> select count(id_order) + 1 from sometable WHERE id_order LIKE 'O-20110704
> -%';
>
> If you do this inside a function it will be like running it in a
> transaction so you shouldn't have to worry about it being a multi-user
> system.
>
>
>

I like this - looks better than what I'm currently doing. Thanks
Johnf

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Samuel Gendler 2011-07-06 00:41:25 Re: interesting sequence
Previous Message Viktor Bojović 2011-07-05 20:29:03 overload