mirror of https://github.com/BRAVO68WEB/shx.git
17 lines
410 B
PL/PgSQL
17 lines
410 B
PL/PgSQL
create function unique_random(len int, _table text, _col text) returns text as $$
|
|
declare
|
|
result text;
|
|
numrows int;
|
|
begin
|
|
result = random_string(len);
|
|
loop
|
|
execute format('select 1 from %I where %I = %L', _table, _col, result);
|
|
get diagnostics numrows = row_count;
|
|
if numrows = 0 then
|
|
return result;
|
|
end if;
|
|
result = random_string(len);
|
|
end loop;
|
|
end;
|
|
$$ language plpgsql;
|