pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hannu Krosing <hannu@2ndQuadrant.com>
To: Віталій Тимчишин <tivv00@gmail.com>
Cc: Peter <peter@greatnowhere.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Totally weird behaviour in org.postgresql.Driver
Date: Tue, 17 Mar 2009 14:05:19 +0200
Message-ID: <1237291519.13493.10.camel@huvostro> (raw)
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>

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




view thread (22+ messages)  latest in thread

Message-ID: <1237291519.13493.10.camel@huvostro>
Permalink:  ../1237291519.13493.10.camel@huvostro/
Also on:    postgresql.org/message-id/1237291519.13493.10.camel@huvostro

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: hannu@2ndQuadrant.com, tivv00@gmail.com, peter@greatnowhere.com
  Subject: Re: Totally weird behaviour in org.postgresql.Driver
  In-Reply-To: <1237291519.13493.10.camel@huvostro>
  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> <1237291519.13493.10.camel@huvostro>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox