Difference between revisions of "Postgres uuid"
Jump to navigation
Jump to search
Line 6: | Line 6: | ||
``` | ``` | ||
+ | ``` | ||
+ | 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; | ||
+ | ``` | ||
``` | ``` |
Revision as of 15:29, 2 April 2023
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;