Set role dynamically from proc

From: Durumdara <durumdara(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Set role dynamically from proc
Date: 2017-11-22 13:55:31
Message-ID: CAEcMXhkON0g+0a8y05ZyhAi9HxQrxKU+gp8zjxC9+S0dPpALmA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephen Frost 2017-11-22 14:07:18 Re: migrations (was Re: To all who wish to unsubscribe)
Previous Message Rakesh Kumar 2017-11-22 13:50:35 testing