From: | Hannu Krosing <hannu(at)2ndQuadrant(dot)com> |
---|---|
To: | Віталій Тимчишин <tivv00(at)gmail(dot)com> |
Cc: | Peter <peter(at)greatnowhere(dot)com>, pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: Totally weird behaviour in org.postgresql.Driver |
Date: | 2009-03-17 12:05:19 |
Message-ID: | 1237291519.13493.10.camel@huvostro |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
On Tue, 2009-03-17 at 13:41 +0200, Віталій Тимчишин wrote:
>
>
> 2009/3/17 Peter <peter(at)greatnowhere(dot)com>
>
> So is there a way to associate user variable with Postgres
> connection that
> can be picked up by SQL code running in that connection? Right
> now I can
> only think of PlPerl function that caches user id in a global
> variable, but
> am not sure about potential pitfalls of such setup...
>
> You could use temporary table.
> E.g. create temporary table localdata(name, value) as select
> values('user', 'john');
> This will be connection-scope.
Or use pl/python and its global dictionaries, write 2 functions
hannu=# create function set_current_web_user(username text) returns void
as $$
GD['current_web_user'] = username;
$$ language plpythonu security definer;
CREATE FUNCTION
hannu=# create function get_current_web_user() returns text as $$
hannu$# return GD['current_web_user']
hannu$# $$ language plpythonu security definer;
CREATE FUNCTION
hannu=# select get_current_web_user();
ERROR: plpython: function "get_current_web_user" failed
DETAIL: <type 'exceptions.KeyError'>: 'current_web_user'
hannu=# select set_current_web_user('adalbert');
set_current_web_user
----------------------
(1 row)
hannu=# select get_current_web_user();
get_current_web_user
----------------------
adalbert
(1 row)
GD has session scope.
--
Hannu Krosing http://www.2ndQuadrant.com
PostgreSQL Scalability and Availability
Services, Consulting and Training
From | Date | Subject | |
---|---|---|---|
Next Message | Guy Rouillier | 2009-03-17 17:05:12 | Re: Totally weird behaviour in org.postgresql.Driver |
Previous Message | Віталій Тимчишин | 2009-03-17 11:41:50 | Re: Totally weird behaviour in org.postgresql.Driver |