B
B
belyy_shum2021-05-22 00:47:01
PostgreSQL
belyy_shum, 2021-05-22 00:47:01

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

2 answer(s)
S
Student18ru, 2021-05-22
@Student18ru

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.

G
galaxy, 2021-05-22
@galaxy

I don't know what exactly you need. The following function returns an arbitrary length string lenfrom 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 question

Ask a Question

731 491 924 answers to any question