Re: storing plpython global pointer

Lists: pgsql-hackers
From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: storing plpython global pointer
Date: 2013-05-28 12:04:00
Message-ID: CAFjNrYuBE1BqvvHdYCvbfts+D99xvWOaM0i0FEnf2DRWTBgNuA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,
I need to store a global pointer for plpython usage. This is a PyObject*
which can be initialized per session I think, as we have to deal with
Python 2 and Python 3. This pointer points to a Python constructor of
Python's Decimal type, taken from python stdlib.

I've got working code, however loading python module each time there is
Numeric argument in plpython function is not very efficient, so I'd like to
do it once and keep this somewhere. This has no side effects as this is a
pointer to a pure function.

Where should I keep such a pointer?

thanks,
Szymon


From: Jan Urbański <wulczer(at)wulczer(dot)org>
To: Szymon Guz <mabewlun(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: storing plpython global pointer
Date: 2013-05-28 12:15:01
Message-ID: 51A49FC5.3080106@wulczer.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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


From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: Jan Urbański <wulczer(at)wulczer(dot)org>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: storing plpython global pointer
Date: 2013-05-28 12:22:13
Message-ID: CAFjNrYuzRSi2c_4=+qvV2qDNLkmY6_Qs_Ghq4QqSFa7rzfARjg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 28 May 2013 14:15, Jan Urbański <wulczer(at)wulczer(dot)org> wrote:

> 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
>

I think I'd rather go with the first solution, as this function should not
be accessible inside the plpython function. That's what I was thinking
about as well, but I wasn't sure.

thanks,
Szymon