pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ALTER ROLE ... SET in current database only
3+ messages / 2 participants
[nested] [flat]

* ALTER ROLE ... SET in current database only
@ 2021-02-15 17:25  Wolfgang Walther <walther@technowledgy.de>
  0 siblings, 1 reply; 3+ messages in thread

From: Wolfgang Walther @ 2021-02-15 17:25 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Hi,

I'm trying to set a GUC for a role in the current database only - but 
don't know the name of the database at the time of writing code. Could 
be development, staging, ...

I would basically like to do something like this:

ALTER ROLE a IN CURRENT DATABASE SET b TO c;

Although that syntax doesn't exist (yet).

I think I could wrap it in a DO block and create the statement 
dynamically. Alternatively, I could probably INSERT INTO / UPDATE 
pg_db_role_setting manually?

Any other ideas how to achieve this easily? Does the proposed "IN 
CURRENT DATABASE" syntax sound useful to anyone else?

Best,

Wolfgang





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: ALTER ROLE ... SET in current database only
@ 2021-02-16 06:32  Abdul Qoyyuum <aqoyyuum@cardaccess.com.au>
  parent: Wolfgang Walther <walther@technowledgy.de>
  0 siblings, 1 reply; 3+ messages in thread

From: Abdul Qoyyuum @ 2021-02-16 06:32 UTC (permalink / raw)
  To: Wolfgang Walther <walther@technowledgy.de>; +Cc: pgsql-general@lists.postgresql.org

Wouldnt you need to connect to the database first before you can ALTER ROLE
anything?

On Tue, Feb 16, 2021 at 1:25 AM Wolfgang Walther <walther@technowledgy.de>
wrote:

> Hi,
>
> I'm trying to set a GUC for a role in the current database only - but
> don't know the name of the database at the time of writing code. Could
> be development, staging, ...
>
> I would basically like to do something like this:
>
> ALTER ROLE a IN CURRENT DATABASE SET b TO c;
>
> Although that syntax doesn't exist (yet).
>
> I think I could wrap it in a DO block and create the statement
> dynamically. Alternatively, I could probably INSERT INTO / UPDATE
> pg_db_role_setting manually?
>
> Any other ideas how to achieve this easily? Does the proposed "IN
> CURRENT DATABASE" syntax sound useful to anyone else?
>
> Best,
>
> Wolfgang
>
>
>

-- 
Abdul Qoyyuum Bin Haji Abdul Kadir
HP No: +673 720 8043

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: ALTER ROLE ... SET in current database only
@ 2021-02-16 08:41  Wolfgang Walther <walther@technowledgy.de>
  parent: Abdul Qoyyuum <aqoyyuum@cardaccess.com.au>
  0 siblings, 0 replies; 3+ messages in thread

From: Wolfgang Walther @ 2021-02-16 08:41 UTC (permalink / raw)
  To: Abdul Qoyyuum <aqoyyuum@cardaccess.com.au>; +Cc: pgsql-general@lists.postgresql.org

Abdul Qoyyuum:
> Wouldnt you need to connect to the database first before you can ALTER 
> ROLE anything?

Of course, otherwise the notion of "current database" wouldn't make 
sense at all. But that's only before executing the code. I am not 
writing and executing this code at the same time.

In my case I'm seeding a postgres docker container with settings and 
data on first launch. The database name is passed to the container via 
environment variable. But, I'm sure there are other use-cases where code 
should be written once, but be executed in different databases.

Best,

Wolfgang





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2021-02-16 08:41 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-02-15 17:25 ALTER ROLE ... SET in current database only Wolfgang Walther <walther@technowledgy.de>
2021-02-16 06:32 ` Abdul Qoyyuum <aqoyyuum@cardaccess.com.au>
2021-02-16 08:41   ` Wolfgang Walther <walther@technowledgy.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox