Answer the question
In order to leave comments, you need to log in
How to form arbitrary rows of data when executing a query?
Formation of arbitrary data strings when executing a query
Answer the question
In order to leave comments, you need to log in
As far as I know, databases don't generate any arbitrary string data. This data is generated on the server side. You can use timestamp and then hash it. Thus, depending on what algorithm you will hash all this with, you will get a unique string of a certain length.
I don't know what exactly you need. The following function returns an arbitrary length string len
from alphabetic characters chars
:
create or replace function rand_str(len int, chars text default '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') returns text language sql as $$
SELECT string_agg (substr(chars, ceil (random() * length(chars))::integer, 1), '')
FROM generate_series(1, len)
$$;
postgres=# select rand_str(10);
rand_str
------------
wmIn59AeiS
(1 row)
postgres=# select rand_str(50, 'абвгдежзиклмнопрстуфхцчшщъыьэюя');
rand_str
----------------------------------------------------
дломчяочэатьщсдмллянблнцммюгььжзетшбзвшлежлэщдечют
(1 row)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question