Re: Set role dynamically from proc

From: Durumdara <durumdara(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Set role dynamically from proc
Date: 2017-11-22 14:52:45
Message-ID: CAEcMXhkT8L_+MYLsOiEr2JWWW+pt_LyNkkuA=ooTSvo0_YDmFQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello!

I haven't got your mail, I see your answer only in the thread of web
mailing list.

> It seems that the user does not exist:

The problem is based on that I want to set the role to the database owner
from script.
My team members many times logged as "postgres" or diff user, and forget to
set the role to DB owner.
I thought I can avoid the problems with changing the actual role to real
owner before the changes.

Now the "set role" uses the "variable name", and not the "value of the
variable".

This is what I don't like in this lang. I need to write a special variable
name to "force" to use it, and not other thing.
I don't know how to force the system to use my variable value, and not my
variable name in the routines.
For example $var$, or <var>, or [var], etc.

I can generate "set role" with string concat, but in PGAdmin this script
would be good.

Thank you!
dd

2017-11-22 14:55 GMT+01:00 Durumdara <durumdara(at)gmail(dot)com>:

> 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
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adam Brusselback 2017-11-22 14:59:52 [GENERAL] postgres_fdw & could not receive data from client: Connection reset by peer
Previous Message Tom Lane 2017-11-22 14:43:19 Re: migrations (was Re: To all who wish to unsubscribe)