I'm using this SQL query to generate random value in PostgreSQL
chr(ascii('B') + (random() * 25)::integer)
How I can generate 15 characters random String using the same query?
The PostgreSQL MD5() function is used to evaluate the MD5 hash of a string and subsequently return the result. The result is generally in hexadecimal form. Syntax: MD5(string) Let's analyze the above syntax: The string argument is the string of which the MD5 hash is calculated.
Another solution that's pretty easy to read (perf should be reasonable, but no benchmarks were performed):
select substr(md5(random()::text), 0, 25);
Could be uppercased if you prefer:
select upper(substr(md5(random()::text), 0, 25));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With