Thread: storing plpython global pointer

storing plpython global pointer

From
Szymon Guz
Date:
<div dir="ltr">Hi,<div style="style">I need to store a global pointer for plpython usage. This is a PyObject* which can
beinitialized per session I think, as we have to deal with Python 2 and Python 3. This pointer points to a Python
constructorof Python's Decimal type, taken from python stdlib.</div><div style="style"><br /></div><div
style="style">I'vegot working code, however loading python module each time there is Numeric argument in plpython
functionis not very efficient, so I'd like to do it once and keep this somewhere. This has no side effects as this is a
pointerto a pure function.</div><div style="style"><br /></div><div style="style">Where should I keep such a
pointer?</div><divstyle="style"><br /></div><div style="style">thanks,</div><div style="style">Szymon</div></div> 

Re: storing plpython global pointer

From
Jan Urbański
Date:
On 28/05/13 14:04, Szymon Guz wrote:
> Hi,
> I need to store a global pointer for plpython usage. This is a PyObject*
> which can be initialized per session I think
>
> Where should I keep such a pointer?

Hi,

you probably could use a global variable, similar to PLy_interp_globals 
that's defined in plpy_main.c.

Another method would be to expose the Decimal constructor in the plpy 
module. You could modify plpy_plpymodule.c to import decimal and expose 
the Decimal constructor as plpy.Decimal.

Best,
Jan



Re: storing plpython global pointer

From
Szymon Guz
Date:
<div dir="ltr">On 28 May 2013 14:15, Jan Urbański <span dir="ltr"><<a href="mailto:wulczer@wulczer.org"
target="_blank">wulczer@wulczer.org</a>></span>wrote:<br /><div class="gmail_extra"><div
class="gmail_quote"><blockquoteclass="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex"><divclass="im">On 28/05/13 14:04, Szymon Guz wrote:<br /></div><blockquote class="gmail_quote"
style="margin:00 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"> Hi,<br /> I need to store a
globalpointer for plpython usage. This is a PyObject*<br /> which can be initialized per session I think<br /><br
/></div><divclass="im"> Where should I keep such a pointer?<br /></div></blockquote><br /> Hi,<br /><br /> you probably
coulduse a global variable, similar to PLy_interp_globals that's defined in plpy_main.c.<br /><br /> Another method
wouldbe to expose the Decimal constructor in the plpy module. You could modify plpy_plpymodule.c to import decimal and
exposethe Decimal constructor as plpy.Decimal.<br /><br /> Best,<br /> Jan<br /></blockquote></div><br /></div><div
class="gmail_extra"style="style">I think I'd rather go with the first solution, as this function should not be
accessibleinside the plpython function. That's what I was thinking about as well, but I wasn't sure.</div><div
class="gmail_extra"style="style"><br /></div><div class="gmail_extra" style="style">thanks,</div><div
class="gmail_extra"style="style">Szymon</div></div>