plpython attypmod broken in MODIFY trigger returns

From: Bradley McLean <brad(at)bradm(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: plpython attypmod broken in MODIFY trigger returns
Date: 2003-02-13 00:34:13
Message-ID: 20030213003413.GA2512@nia.bradm.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

In a plpython trigger, if you return "MODIFY", the parsing of the
TD["new"] dictionary uses the wrong (c array) index to locate the
atttypmod value, leading to subtle bugs dependent on the exact types,
names, and order of fields in the table in question.

(Types need to be those that use the typmod, names affect the ordering
in the python dictionary, and order affects the c array).

In my case, I ended up with TIMESTAMP(68), which was just slightly
more precision than I really wanted ;-)

Here's a patch that fixes my issue. I have not extensively developed
tests for it.

-Brad

-----

diff -ur postgresql-7.3.2.orig/src/pl/plpython/plpython.c postgresql-7.3.2/src/pl/plpython/plpython.c
--- postgresql-7.3.2.orig/src/pl/plpython/plpython.c Fri Jan 31 17:35:27 2003
+++ postgresql-7.3.2/src/pl/plpython/plpython.c Wed Feb 12 19:22:08 2003
@@ -630,7 +630,7 @@
modvalues[j] = FunctionCall3(&proc->result.out.r.atts[atti].typfunc,
CStringGetDatum(src),
ObjectIdGetDatum(proc->result.out.r.atts[atti].typelem),
- Int32GetDatum(tupdesc->attrs[j]->atttypmod));
+ Int32GetDatum(tupdesc->attrs[atti]->atttypmod));
modnulls[j] = ' ';

Py_DECREF(plstr);

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Justin Clift 2003-02-13 00:53:29 Re: Brain dump: btree collapsing
Previous Message Sumaira Ali 2003-02-13 00:19:29 lock method