Thread: Bug #963: Weird plpython trigger(?) behaviour in 7.3.2

Bug #963: Weird plpython trigger(?) behaviour in 7.3.2

From
pgsql-bugs@postgresql.org
Date:
Indrek Jarve (incx@inversion.ee) reports a bug with a severity of 3
The lower the number the more severe it is.

Short Description
Weird plpython trigger(?) behaviour in 7.3.2

Long Description
Hi,

using an plpython BEFORE INSERT FOR EACH ROW trigger that modifies the
inserted row on the schema attached below seems to cause weird side effects: when the trigger modifies field1 (in this
casevarchar(300)) contents to be longer than the size of field2 (in this case varchar(16)), the backend refuses to
insertthe row and replies: "ERROR: value too long for type character varying(16)", even when field2 is a shorter string
andis NOT modified by the trigger. Removing the limit from field2 (for example declaring it as text) causes the error
todisappear.  

System: Redhat 9 with updates on a dual-p3, PostgreSQL 7.3.2 installed from RPM packages that came with it.

Regards,
Indrek

Sample Code
Used SQL:

CREATE TABLE items (
    field1 character varying(300),
    field2 varchar(16)
);

CREATE FUNCTION test_func () RETURNS "trigger"
    AS '
# Set field1 LONGER than 16 chars
TD[''new''][''field1''] = ''aabaaaaaaaaaaaaaaa''
return ''MODIFY''
'
    LANGUAGE plpython;

COPY items (field1, field2) FROM stdin;
asdf1   asdf2
\.

CREATE TRIGGER test_trig
    BEFORE INSERT ON items
    FOR EACH ROW
    EXECUTE PROCEDURE test_func ();

insert into items ( field2 ) values ( '' );

psql result:

[incx@hercules incx]$ psql incx < bugine.txt
CREATE TABLE
CREATE FUNCTION
CREATE TRIGGER
ERROR:  value too long for type character varying(16)

No file was uploaded with this report

Re: Bug #963: Weird plpython trigger(?) behaviour in 7.3.2

From
Tom Lane
Date:
pgsql-bugs@postgresql.org writes:
> Weird plpython trigger(?) behaviour in 7.3.2

The given test case works for me using CVS tip.  I think it was probably
the same bug reported and fixed by Brad McLean in February.  You can get
the correction from
http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/pl/plpython/plpython.c
or wait for 7.3.3...

            regards, tom lane