Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 66F2F6339E6 for ; Tue, 17 Mar 2009 09:08:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 82107-06 for ; Tue, 17 Mar 2009 09:07:54 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.televork.ee (mail.televork.ee [81.21.241.190]) by mail.postgresql.org (Postfix) with ESMTP id 42CCA63259C for ; Tue, 17 Mar 2009 09:08:00 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mail.televork.ee (Postfix) with ESMTP id 82B07185AF9; Tue, 17 Mar 2009 14:08:09 +0200 (EET) X-Virus-Scanned: at mail.televork.ee Received: from mail.televork.ee ([81.21.241.190]) by localhost (mail.televork.ee [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Voyyg62LLf-Q; Tue, 17 Mar 2009 14:08:01 +0200 (EET) Received: from [127.0.0.1] (81-21-242-98.televork.ee [81.21.242.98]) by mail.televork.ee (Postfix) with ESMTP id 7F9E83CAB9; Tue, 17 Mar 2009 14:05:34 +0200 (EET) Subject: Re: Totally weird behaviour in org.postgresql.Driver From: Hannu Krosing To: =?UTF-8?Q?=D0=92=D1=96=D1=82=D0=B0=D0=BB=D1=96=D0=B9_?= =?UTF-8?Q?=D0=A2=D0=B8=D0=BC=D1=87=D0=B8=D1=88=D0=B8=D0=BD?= Cc: Peter , pgsql-jdbc@postgresql.org In-Reply-To: <331e40660903170441o2f52f36fpb18dcf94ff88d37a@mail.gmail.com> References: <49b7bfef$0$1343$834e42db@reader.greatnowhere.com> <491f66a50903120342j67e87c7dob10cfdc23580c8f4@mail.gmail.com> <003001c9a315$a68a9330$f39fb990$@com> <200903121341.59498.cservin@cromagnon.com> <49bca9e8$0$1341$834e42db@reader.greatnowhere.com> <491f66a50903150409y648b448pc3825ef4fc1ed7e@mail.gmail.com> <49bcfe15$0$1344$834e42db@reader.greatnowhere.com> <49BDABC7.3030108@burntmail.com> <491f66a50903160257m3cd01c07v828a33fab173e775@mail.gmail.com> <49bf5e7f$0$1347$834e42db@reader.greatnowhere.com> <331e40660903170441o2f52f36fpb18dcf94ff88d37a@mail.gmail.com> Content-Type: text/plain; charset="UTF-8" Date: Tue, 17 Mar 2009 14:05:19 +0200 Message-Id: <1237291519.13493.10.camel@huvostro> Mime-Version: 1.0 X-Mailer: Evolution 2.24.3 Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/89 X-Sequence-Number: 19419 On Tue, 2009-03-17 at 13:41 +0200, Віталій Тимчишин wrote: > > > 2009/3/17 Peter > > 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: : '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