I currently use Firebird SQL as the db backend of my shareware, would like to support also PG 9.3+.
In FB I use set/get_context to do this:
set-context
get-context
e.g. I would do this after a user logs in:
select rdb$set_context('USER_SESSION', 'LANGUAGE_ID', %s) \
from rdb$database" % appobj.loggedInUser.language.id
In some of my views I would then use:
... AND t.fk_language_id=rdb$get_context('USER_SESSION', 'LANGUAGE_ID')
I searched through PG doc and did some googling but didn't find a solution yet.
Would appreciate any tips. Werner
You can use a session variables in custom schema:
postgres=# set myvars.language_id = 10;
SET
postgres=# show myvars.language_id;
myvars.language_id
--------------------
10
(1 row)
or via functions (http://www.postgresql.org/docs/9.4/static/functions-admin.html):
postgres=# select set_config('myvars.language_id', '20', false);
set_config
------------
20
(1 row)
postgres=# select current_setting('myvars.language_id');
current_setting
-----------------
20
(1 row)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With