interesting sequence - Mailing list pgsql-sql

From John Fabiani
Subject interesting sequence
Date
Msg-id 201107050652.22187.johnf@jfcomputer.com
Whole thread Raw
Responses Re: interesting sequence  (Samuel Gendler <sgendler@ideasculptor.com>)
Re: interesting sequence  (Gavin Flower <GavinFlower@archidevsys.co.nz>)
List pgsql-sql
Hi,

I have a special need to create a sequence like function.

"O-20110704 -2"  which is 
"O" for order (there are other types)
"20110704" is for July 4, 2011
'2' the second order of the day for July 4, 2011

I of course can get the type and date.  What I don't know is how to get is the 
last number.  It would seem to be that I would need a loop to determine if the 
next number existed.

LOOP
--Check to see if the string exist in a table
-- count = count +1
-- until I don't find the string
END LOOP;

but then I thought I could do something like

for $1 in  (select string from sometable)LOOPcount = count + 1

or something like this

for i in 1..999 LOOP-- check for the existence of the string in a table using 'i'
-- there will never be 999 orders in one day.
END LOOP    


So here is the question what would be the best way for a multi-user system?
If someone has a better thought - it would be helpful.

BTW I did NOT design the number - in fact it seems silly to me.

Johnf




pgsql-sql by date:

Previous
From: gmb
Date:
Subject: Re: Usage of function retruning record in query
Next
From: Samuel Gendler
Date:
Subject: Re: interesting sequence