session persistent data for plperl - Mailing list pgsql-hackers

From Andrew Dunstan
Subject session persistent data for plperl
Date
Msg-id 402672F4.4050905@dunslane.net
Whole thread Raw
Responses Re: session persistent data for plperl  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers
The attached tiny patch (not intended for application yet) provides a 
space for plperl functions to create and share session persistent data, 
which I should think would increase the utility of plperl. Essentially 
it creates a hash called %session_globals which it then injects into the 
safe container where plperl functions live.

Comments are welcome - this is just a proof of concept. If this seems 
good to people, I will try to use a similar mechanism to "register" 
plperl functions so they can call each other.

cheers

andrew

(stupid) example use (using dollar quoting in psql ;-) ):

andrew=# create function perlfunc() returns text language plperl as $$
andrew$# if (!exists $session_globals{x}) { $session_globals{x} = 
'abcxyz'; }
andrew$# return $session_globals{x}++;
andrew$# $$;
CREATE FUNCTION
andrew=# select perlfunc();perlfunc
----------abcxyz
(1 row)

andrew=# select perlfunc();perlfunc
----------abcxza
(1 row)

andrew=# create function perlfunc2() returns text language plperl as $$
andrew$# if (!exists $session_globals{x}) { $session_globals{x} = 
'abcxyz'; }
andrew$# $session_globals{x} = reverse $session_globals{x};
andrew$# return $session_globals{x}++;
andrew$# $$;
CREATE FUNCTION
andrew=# select perlfunc2();perlfunc2
-----------bzxcba
(1 row)

andrew=# select perlfunc2();perlfunc2
-----------bbcxzb
(1 row)

andrew=# select perlfunc();perlfunc
----------bbcxzc
(1 row)




pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: Kerberos as source of user name? (Re: [BUGS] segfault in psql on x86_64)
Next
From: Andrew Dunstan
Date:
Subject: Re: session persistent data for plperl