Answer the question
In order to leave comments, you need to log in
Generate unique value?
Hello. Can you please tell me the best way to solve this problem? There is a field in the table 'serialNumber' STRING(9), and when creating a record, it is necessary to generate a unique value that is not in the database, the size of the field is 9 characters, and the possible characters are "0-9".
As an option, of course, you can create a random number in a trigger, in a loop, and then make a selection in the table for the presence of this number, until the selection returns an empty record.
But maybe there is a better solution?
P.S. There is one nuance, the numbers should not be in a row, it will be something like a serial number for a license
Answer the question
In order to leave comments, you need to log in
create sequence serial_number_seq minvalue 1 maxvalue 999999999;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question