dbTalk Databases Forums  

[BUGS] plpython triggers TD["new"] = None

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] plpython triggers TD["new"] = None in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Lee Jensen
 
Posts: n/a

Default [BUGS] plpython triggers TD["new"] = None - 01-27-2005 , 04:21 PM






I have postgres 7.4.6 installed on 2 machines one debian and one
freebsd. Both are the most recent installs of each OS. On both I have
the plpython module and both are having the same issue. Essentially when
a function is called from a trigger the TD tuple get's populated with
all the standard data except new and old have no value (None). Here is
the function code I am working with:

CREATE OR REPLACE FUNCTION public.test_trigger() RETURNS trigger AS
'
plpy.error(TD)

return "OK"
' LANGUAGE 'plpythonu';

The actual trigger is defined as follows:
CREATE TRIGGER trig
BEFORE INSERT OR UPDATE
ON public.test
FOR EACH STATEMENT
EXECUTE PROCEDURE public.test_trigger();

The following error is generated on both machines when an insert occurs:
ERROR: plpython: function "test_trigger" failed
DETAIL: plpy.Error: ({'relid': '17246', 'old': None, 'name': 'trig',
'level': 'STATEMENT', 'args': None, 'when': 'BEFORE', 'new': None,
'event': 'INSERT'},)

Any help would be appreciated. Most likely I've done something wrong
somewhere.

Lee

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Reply With Quote
  #2  
Old   
Michael Fuhr
 
Posts: n/a

Default Re: [BUGS] plpython triggers TD["new"] = None - 01-27-2005 , 04:36 PM






On Thu, Jan 27, 2005 at 03:13:27PM -0700, Lee Jensen wrote:

Quote:
I have postgres 7.4.6 installed on 2 machines one debian and one
freebsd. Both are the most recent installs of each OS. On both I have
the plpython module and both are having the same issue. Essentially when
a function is called from a trigger the TD tuple get's populated with
all the standard data except new and old have no value (None). Here is
the function code I am working with:
[snip]

Quote:
CREATE TRIGGER trig
BEFORE INSERT OR UPDATE
ON public.test
FOR EACH STATEMENT
^^^^^^^^^
EXECUTE PROCEDURE public.test_trigger();
OLD and NEW don't make sense in statement-level triggers because
the statement could affect many rows. Use FOR EACH ROW if you need
to access the row values.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings


Reply With Quote
  #3  
Old   
Alvaro Herrera
 
Posts: n/a

Default Re: [BUGS] plpython triggers TD["new"] = None - 01-27-2005 , 04:42 PM



On Thu, Jan 27, 2005 at 03:13:27PM -0700, Lee Jensen wrote:
Quote:
I have postgres 7.4.6 installed on 2 machines one debian and one
freebsd. Both are the most recent installs of each OS. On both I have
the plpython module and both are having the same issue. Essentially when
a function is called from a
.... [FOR EACH STATEMENT] ...
trigger the TD tuple get's populated with
all the standard data except new and old have no value (None). Here is
the function code I am working with:
Statement level triggers don't have access to NEW nor OLD. Only row
level triggers do ...

--
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
"I suspect most samba developers are already technically insane...
Of course, since many of them are Australians, you can't tell." (L. Torvalds)

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
  #4  
Old   
Alvaro Herrera
 
Posts: n/a

Default Re: [BUGS] plpython triggers TD["new"] = None - 01-27-2005 , 04:51 PM



On Thu, Jan 27, 2005 at 03:34:55PM -0700, Michael Fuhr wrote:

Quote:
OLD and NEW don't make sense in statement-level triggers because
the statement could affect many rows. Use FOR EACH ROW if you need
to access the row values.
IMHO they do make sense. It's just that they haven't been implemented.

--
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
"El miedo atento y previsor es la madre de la seguridad" (E. Burke)

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org


Reply With Quote
  #5  
Old   
Alvaro Herrera
 
Posts: n/a

Default Re: [BUGS] plpython triggers TD["new"] = None - 01-27-2005 , 05:14 PM



On Thu, Jan 27, 2005 at 04:01:32PM -0700, Michael Fuhr wrote:
Quote:
On Thu, Jan 27, 2005 at 07:46:54PM -0300, Alvaro Herrera wrote:
On Thu, Jan 27, 2005 at 03:34:55PM -0700, Michael Fuhr wrote:

OLD and NEW don't make sense in statement-level triggers because
the statement could affect many rows. Use FOR EACH ROW if you need
to access the row values.

IMHO they do make sense. It's just that they haven't been implemented.

What do you have in mind? What would OLD and NEW refer to in
statements that affect multiple rows? Are you thinking of a way
to refer to all of the old and new rows?
Yes, exactly that. They would be arrays of tuples (or whatever they are
called in Python -- I'm not thinking specifically in Python.)

--
Alvaro Herrera (<alvherre[@]dcc.uchile.cl>)
"Escucha y olvidarás; ve y recordarás; haz y entenderás" (Confucio)

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend


Reply With Quote
  #6  
Old   
Michael Fuhr
 
Posts: n/a

Default Re: [BUGS] plpython triggers TD["new"] = None - 01-27-2005 , 05:29 PM



On Thu, Jan 27, 2005 at 08:11:50PM -0300, Alvaro Herrera wrote:
Quote:
On Thu, Jan 27, 2005 at 04:01:32PM -0700, Michael Fuhr wrote:

What do you have in mind? What would OLD and NEW refer to in
statements that affect multiple rows? Are you thinking of a way
to refer to all of the old and new rows?

Yes, exactly that. They would be arrays of tuples (or whatever they are
called in Python -- I'm not thinking specifically in Python.)
Right...when I saw your first response I started digging around one
of the standards and saw references to old and new transition tables
for statement-level triggers. That would be handy if it could be
implemented without scalability problems.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.