In article <1574570229(dot)20040420095643(at)radax(dot)net>,
Enrico Ortmann <pg(dot)admin(at)radax(dot)net> writes:
> Hi admins,
> I got a conceptual question on creating a stored procedure
> I need for my app. First the description of the problem:
> I need a counter which works with 36 possible values per
> character [0-9 and thereafter A-Z].
> That means if incremented it should return values as follows:
> and so on.
> My question is if anybody has already implemented such a
> user-defined 'sequence' in PL/PGSql or if anyone has a great
> idea on how to do that. The only solution I see at present is
> to do that in PHP which is used to code the mentioned userland.
> I suggest to solute on doing the following.
> - I create a sequence on the DBS
> - I get the next value of this sequence
> - I convert the next value in PHP in the code I need
> The problem I see on doing this is that I always need to
> convert if I want to get any kind of information about the
> counter. For example it could be that I only want to know
> what the last given value was. Because of the high traffic
> value on the application I have to take care of, that the
> information I read is quite correct at any time. So if I
> have to convert the value of the sequence therefore I need
> a little time. In the meantime the value could have changed
> and my information is worthless.
> I think the best way would be to code a store procedure
> for the problem. Any ideas would be welcome.
You could use an ordinary sequence internally and translate the
sequential values to your representation on output, like that:
SELECT num / 36 ||
WHEN num % 36 < 10 THEN chr ((num % 36) + ascii ('0'))
ELSE chr ((num % 36) - 10 + ascii ('A'))
Me thinks this might be the most efficient way to deal with that.
In response to
pgsql-admin by date
|Next:||From: Bruce Momjian||Date: 2004-04-20 15:25:51|
|Subject: pg_autovacuum crashes when query fails for temp tables|
|Previous:||From: Raquel Vieira||Date: 2004-04-20 13:52:19|