From: John Fabiani <johnf@jfcomputer.com>
To: pgsql-sql@postgresql.org
Subject: interesting sequence
Date: Tue, 5 Jul 2011 06:52:22 -0700
Message-ID: <201107050652.22187.johnf@jfcomputer.com> (raw)
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)
LOOP
count = 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
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: <201107050652.22187.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