Set role dynamically from proc - Mailing list pgsql-general

From Durumdara
Subject Set role dynamically from proc
Date
Msg-id CAEcMXhkON0g+0a8y05ZyhAi9HxQrxKU+gp8zjxC9+S0dPpALmA@mail.gmail.com
Whole thread Raw
Responses RE: Set role dynamically from proc
Re: Set role dynamically from proc
List pgsql-general
Hello!

May you know the way how to set role dynamically.

DO 
$$
DECLARE act_dbowner varchar(100);
BEGIN

SELECT u.usename into act_dbowner FROM pg_database d
JOIN pg_user u ON (d.datdba = u.usesysid)
WHERE d.datname = (SELECT current_database());
raise notice 'DB owner: %', act_dbowner;

set role to act_dbowner; --  THIS LINE
END
$$;

-------------

ERROR:  role "act_dbowner" does not exist
CONTEXT:  SQL statement "set role to act_dbowner"
PL/pgSQL function inline_code_block line 10 at SQL statement

I try to use $act_dbowner, but it have no effect.

Thank you for your help!

Best wishes
   dd

pgsql-general by date:

Previous
From: "Rakesh Kumar"
Date:
Subject: testing
Next
From: Stephen Frost
Date:
Subject: Re: migrations (was Re: To all who wish to unsubscribe)