pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John Fabiani <johnf@jfcomputer.com>
To: pgsql-sql@postgresql.org
Subject: Re: interesting sequence
Date: Tue, 5 Jul 2011 14:42:29 -0700
Message-ID: <201107051442.29875.johnf@jfcomputer.com> (raw)
In-Reply-To: <CADwm0aiqCmx59b22XVWbw4yk8SB2LJfTG=ihtX=yeE=0uiFfXw@mail.gmail.com>
References: <201107050652.22187.johnf@jfcomputer.com>
	<CAEV0TzAPfE1_hGEm3sK5Z4o8TS+H6w698DoZmWRRKEoBQo1F8w@mail.gmail.com>
	<CADwm0aiqCmx59b22XVWbw4yk8SB2LJfTG=ihtX=yeE=0uiFfXw@mail.gmail.com>

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



view thread (10+ messages)  latest in thread

Message-ID: <201107051442.29875.johnf@jfcomputer.com>
Permalink:  ../201107051442.29875.johnf@jfcomputer.com/
Also on:    postgresql.org/message-id/201107051442.29875.johnf@jfcomputer.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: johnf@jfcomputer.com
  Subject: Re: interesting sequence
  In-Reply-To: <201107051442.29875.johnf@jfcomputer.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox