1

In this wonderful answer is proposed GUC-pattern to use run-time parameters to detect current user inside trigger (as one solution). It seemed to suit to me too. But problem is: when I declare the variable in postgresql.conf it is usable inside trigger and I can access it from queries, but can't change it:

# SET rkdb.current_user = 'xyzaaa';
ERROR:  syntax error at or near "current_user"
LINE 1: SET rkdb.current_user = 'xyzaaa';

The error message is misleading, so I did not dig it a while, but now it seems this user (database owner) has no permissions to change params set in global configuration.

I can set any other params:

# SET jumala.kama = 24;
SET

And read it back:

# SHOW jumala.kama;
 jumala.kama 
-------------
 24
(1 row)

I can't SHOW globally set params:

# SHOW rkdb.current_user;
ERROR:  syntax error at or near "current_user"
LINE 1: SHOW rkdb.current_user;
                  ^

but I can reach it with current_setting() function:

# select current_setting('rkdb.current_user');
 current_setting 
-----------------
 www
(1 row)

So my guess is, my database owner does not have permissions to access this param. How could I:

  1. set needed permissions?

or even better

  1. set run-time params with database owner rights?
w.k
  • 8,218
  • 4
  • 32
  • 55

1 Answers1

1

current_user is an SQL standard function, so your use of that name confuses the parser.

Either use a different name or surround it with double quotes like this:

rkdb."current_user"
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263