F
F
froosty2015-11-25 17:19:01
PostgreSQL
froosty, 2015-11-25 17:19:01

How to create a sixty-two sequence in postgresql?

Good day. Can you tell me how to create a sequence with base 62 for the primary key in postgresql? That is, for example, the first record in the table will be with ID="1", the 35th record - ID="Z", the 287th record - ID="4d", the 13777th record - ID="3aD" etc. Thanks in advance for your reply.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2015-11-25
@froosty

Make a function to convert int to 62base text
Make a regular SEQUENCE
and default int_to_62base(nextval('lala_seq'::regclass))

A
Alexey Cheremisin, 2015-11-25
@leahch

And for good, there is no way to create an ASCII table using text characters.
There are only 36 characters for letters and numbers, so you have to break off

>>> int("1234567890",62)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: int() base must be >= 2 and <= 36
>>> int("1234567890",36)
107446288850820L
>>>

Or tell me what will be the 36th and 37th records?! Well, the 60th and 61st of course.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question