The following bug has been logged on the website:
Bug reference: 6559
Logged by: Kirill Simonov
Email address: xi@resolvent.net
PostgreSQL version: 9.1.3
Operating system: Debian squeeze+backports
Description:=20=20=20=20=20=20=20=20
A PlPython INSERT trigger fails to modify a row when a column of a composite
type is affected. Worked with 8.4.
Here is a test case:
CREATE TYPE rec_t AS (val INTEGER);
CREATE TABLE tbl (rec rec_t, val INTEGER);
INSERT INTO tbl (val) VALUES (NULL);
INSERT INTO tbl (rec.val) VALUES (NULL);
CREATE LANGUAGE plpythonu;
CREATE OR REPLACE FUNCTION trg() RETURNS trigger
LANGUAGE plpythonu
AS $$
return 'MODIFY';
$$;
CREATE TRIGGER "!trg()"
BEFORE INSERT OR UPDATE ON tbl
FOR EACH ROW
EXECUTE PROCEDURE trg();
INSERT INTO tbl (val) VALUES (NULL);
INSERT INTO tbl (rec.val) VALUES (NULL);
The output:
$ psql
psql (9.1.3)
Type "help" for help.
postgres=3D#=20
postgres=3D# CREATE TYPE rec_t AS (val INTEGER);
CREATE TYPE
postgres=3D# CREATE TABLE tbl (rec rec_t, val INTEGER);
CREATE TABLE
postgres=3D#=20
postgres=3D# INSERT INTO tbl (val) VALUES (NULL);
INSERT 0 1
postgres=3D# INSERT INTO tbl (rec.val) VALUES (NULL);
INSERT 0 1
postgres=3D#=20
postgres=3D# CREATE LANGUAGE plpythonu;
CREATE LANGUAGE
postgres=3D# CREATE OR REPLACE FUNCTION trg() RETURNS trigger
postgres-# LANGUAGE plpythonu
postgres-# AS $$
postgres$# return 'MODIFY';
postgres$# $$;
CREATE FUNCTION
postgres=3D#=20
postgres=3D# CREATE TRIGGER "!trg()"
postgres-# BEFORE INSERT OR UPDATE ON tbl
postgres-# FOR EACH ROW
postgres-# EXECUTE PROCEDURE trg();
CREATE TRIGGER
postgres=3D#=20
postgres=3D# INSERT INTO tbl (val) VALUES (NULL);
INSERT 0 1
postgres=3D# INSERT INTO tbl (rec.val) VALUES (NULL);
ERROR: length of returned sequence did not match number of columns in row
CONTEXT: while modifying trigger row
PL/Python function "trg"