Re: Totally weird behaviour in org.postgresql.Driver
От | Hannu Krosing |
---|---|
Тема | Re: Totally weird behaviour in org.postgresql.Driver |
Дата | |
Msg-id | 1237291519.13493.10.camel@huvostro обсуждение исходный текст |
Ответ на | Re: Totally weird behaviour in org.postgresql.Driver (Віталій Тимчишин <tivv00@gmail.com>) |
Список | pgsql-jdbc |
On Tue, 2009-03-17 at 13:41 +0200, Віталій Тимчишин wrote: > > > 2009/3/17 Peter <peter@greatnowhere.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
В списке pgsql-jdbc по дате отправления: