I suspect you actually mean "arbitrary" unique names. Simple way could be:
INSERT INTO tbl (id, name)
SELECT g, 'name'::text || g || ' surname' || g
FROM generate_series(1, 1000) g;
.. to generate 1000 distinct names - not random at all, but unique.
To generate 100 names consisting of two words with 3 - 10 random letters from A-Z:
INSERT INTO tbl (id, name)
SELECT g%100
,left(string_agg(chr(65 + (random() * 25)::int), ''), 3 + (random() * 7)::int)
|| ' ' ||
left(string_agg(chr(65 + (random() * 25)::int), ''), 3 + (random() * 7)::int)
FROM generate_series(1, 1000) g
GROUP BY 1
ORDER BY 1;
ASCII code of 'A' is 65, the one of 'Z' is 90. Fortunately, the range between spans the basic upper case alphabet. You can find out with the ascii()
function, which is the reverse of chr()
:
SELECT ascii('A')
The second method doesn't guarantee uniqueness, but duplicates are extremely unlikely with just a few hundred names. Eliminating possible duplicates is trivial. Add another SELECT
layer where you GROUP BY name
and pick min(id)
.