I have a function that does an insert when a given action occurs, I am trying to insert random letters together but I am not finding anything related to this, Is it possible to do this in Postgresql?
I have a function that does an insert when a given action occurs, I am trying to insert random letters together but I am not finding anything related to this, Is it possible to do this in Postgresql?
You will have to create a function see the code below:
create or replace function shuffle(text)
returns text language sql as $$
select string_agg(ch, '')
from (
select substr($1, i, 1) ch
from generate_series(1, length($1)) i
order by random()
) s
$$;
insert into pessoas ( nome, criado, obs, sobrenome)values('nome', '2018-01-16 10:53:04.033', '{s, o, p, t}', (select left(shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'), 1)));
The output will look like this:
[QUERY ] create or replace function shuffle(text)
returns text language sql as $$
select string_agg(ch, '')
from (
select substr($1, i, 1) ch
from generate_series(1, length($1)) i
order by random()
) s
$$
[QUERY ] insert into pessoas ( nome, criado, obs, sobrenome)values('nome', '2018-01-16 10:53:04.033', '{s, o, p, t}', (select left(shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'), 1)))
If you have difficulty posting your function;
I hope I have helped;