as the question says, I need postgresql procedure which will generate Some ids like:
AX0
AX1
AX2
.
.
AX9
AXA
AXB
.
.
AXZ
AY0
AY1
.
.
AY9
AYA
AYB
.
.
AZZ
B00
B01
B02
.
.
etc
And the proceedure can also generate next id when given previous, like send AST and return ASU, or 23X to return 23Y……etc.
Example: SELECT db.stored_proceedure(‘AST’);
As a novice, for now all I have is:
with
letters as
(select chr(i) as letter from generate_series(65,90) i),
digits as
(select lpad(i::text,1,'0') as digit from generate_series(0,9) i)
select l1.letter || l2.letter || l3.letter || l4.letter || d.digit
from letters l1
cross join letters l2
cross join letters l3
cross join letters l4
cross join digits d
limit 2000
Which only generate something like:
AAAA8
AAAA9
AAAB0
AAAB1
AAAB2
AAAB3
.....
AAAB8
AAAB9
AAAC0
AAAC1
AAAC2
Gurus in the house, please help. Thanks
3
Answers
For a 3-char value that includes 0-9 and then A-Z you could produce the next value with the query:
Result:
See db<>fiddle.
Change values in line 1 to see more examples.
I did a base36 conversion with PostgreSQL a while back. I thought I had posted it here but cannot find it in my history:
db<>fiddle here
You could do it like this, it would create a string that has all the characters in my case with 4 letters and a number. Then you select as many as you need.
The CTE numberletters defines how many letters there ca be.
this will need some space run with 8 letters.
db<>fiddle here
For incresing you need a lot of con version
db<>fiddle here