Difference between revisions of "Postgres uuid"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
+ | ``` | ||
+ | CREATE OR REPLACE FUNCTION create_role() | ||
+ | RETURNS TEXT AS $$ | ||
+ | DECLARE | ||
+ | _uuid text := (select replace((select gen_random_uuid()::TEXT), '-', '')); | ||
+ | BEGIN | ||
+ | execute format('create role u%s',_uuid); | ||
+ | RETURN _uuid; | ||
+ | END; | ||
+ | $$ LANGUAGE plpgsql; | ||
+ | ``` | ||
+ | |||
``` | ``` | ||
select gen_random_uuid (); | select gen_random_uuid (); |
Latest revision as of 15:38, 2 April 2023
CREATE OR REPLACE FUNCTION create_role() RETURNS TEXT AS $$ DECLARE _uuid text := (select replace((select gen_random_uuid()::TEXT), '-', '')); BEGIN execute format('create role u%s',_uuid); RETURN _uuid; END; $$ LANGUAGE plpgsql;
select gen_random_uuid (); select replace((select gen_random_uuid()::TEXT), '-', '') ;
create or replace function create_user_readonly ( unm varchar, pwd varchar ) returns varchar(10) as $$ begin execute format($f$create role %I login password '%s'$f$,unm,pwd); execute format('alter role %I set transaction_read_only to on',unm); return 'success'; end; $$ language plpgsql;
CREATE OR REPLACE FUNCTION jb() RETURNS TEXT AS $$ DECLARE rtv TEXT := 'test'; _uuid text := (select replace((select gen_random_uuid()::TEXT), '-', '')); BEGIN -- PERFORM 'test'; -- PERFORM uuid; CREATE ROLE _uuid; RETURN _uuid; END; $$ LANGUAGE plpgsql;