Y
Y
YakovSpb2021-09-13 13:03:22
PostgreSQL
YakovSpb, 2021-09-13 13:03:22

How to restart the function if the result is missing a large or small letter, number, symbol?

There is a key generation code, but sometimes an error pops up if there is not enough character, etc.

SELECT string_agg(substring('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,-./:;<=>[email protected][]^', ceil(random() * 85)::integer, 1), '') FROM generate_series(1,32);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-09-13
@rozhnev

Don't worry, take a ready-made extension for PostgreSQL:

create extension if not exists pgcrypto;
select encode(gen_random_bytes(32),'base64');

Test PostgreSQL query

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question