Greetings The problem arose in making the field in a table that will generate a unique value. It is necessary to create a unique value of armor. Is it possible to do this at the Base level or with a trigger, and not with a code. I stumbled upon the uuid command, it works with a regular SELECT but how to do it for the INSERT to the Base?

  • and what doesn't work like that? insert into users values ​​(uuid (), 'data'); - user2455111
  • UUID, UUID_SHORT are unsafe for statement based replication. And what if in the creation trigger use the value of the unique key of the table plus which row: '1001_bron'?, - Alexus
  • What does 'data' mean? I wanted to make somewhere 8-10 characters and 3 letters or no letters at all (but I think it is unsafe without letters) How else can you implement if not uuid? - Den
  • Without letters, I think it is not safe. Explain what kind of security it is about. I think this is a significant moment, and it is better to include it in the question itself. Explain at the same time what it does not suit you. for example, vulgar SERIAL. - Akina
  • I personally do not see the point of storing large strings in the database for the sake of unique values. I would make an ordinary auto-increment ID, and if you need to generate some link on the client, so that the pattern in the generation would not be noticed, add some fixed string, encrypt it with any reversible algorithm (DES, AES, etc.) and apply base64 / 85 / itp encoding to get letters or even hex. when you get it back, you decode it - get an ID - Mike

1 answer 1

I read it, I decided to do it all the same through the code in the INSERT to do: INSERT INTO tbooking ( bookingcode ) VALUES (UUID())