Re: pl/pythonu - Mailing list pgsql-general

From Mike Mascari
Subject Re: pl/pythonu
Date
Msg-id 402A5F8C.8040104@mascari.com
Whole thread Raw
In response to pl/pythonu  ("C G" <csgcsg39@hotmail.com>)
List pgsql-general
C G wrote:

>>> Dear All,
>>>
>>> Could anyone explain why this function does will not work? The error
>>> message is
>>> DETAIL: exceptions.RuntimeError: maximum recursion depth exceeded.
>>>
>>> CREATE FUNCTION testing() RETURNS trigger AS'
>>>
>>> plan=plpy.prepare(''INSERT INTO t1 values ($1)'',[''text''])
>>> plpy.execute(plan,[''blah''])
>>> return ''MODIFY''
>>>
>>> 'LANGUAGE plpythonu;
>>
>>
>> Do you have a trigger on 't1' which invokes testing()?
>>
>> Mike Mascari
>
> I do have a trigger on t1. The function loads into the database OK, but
> when I insert anything into the database I get the error, relating to
> the function.

I don't see anything that will stop the recursion:

a) You insert into t1
b) testing() gets invoked
c) testing inserts into t1
d) testing() gets invoked
e) testing inserts into t1
f) testing() gets invoked

..etc..

If all you are trying to do is modify the value that gets inserted
into t1 when an INSERT occurs, just modify the TD[''new''] record:

CREATE FUNCTION testing() RETURNS trigger AS '

TD[''new''][''field1''] = ''foo''
return ''MODIFY''

' LANGUAGE plpythonu;

where 'field1' is the field to be modified and 'foo' is the value.

HTH,

Mike Mascari











pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: DB cache size strategies
Next
From: Josh Berkus
Date:
Subject: Re: sybase->postgresql