The following bug has been logged on the website:

Bug reference:      6559
Logged by:          Kirill Simonov
Email address:      x...@resolvent.net
PostgreSQL version: 9.1.3
Operating system:   Debian squeeze+backports
Description:        

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=# 
postgres=# CREATE TYPE rec_t AS (val INTEGER);
CREATE TYPE
postgres=# CREATE TABLE tbl (rec rec_t, val INTEGER);
CREATE TABLE
postgres=# 
postgres=# INSERT INTO tbl (val) VALUES (NULL);
INSERT 0 1
postgres=# INSERT INTO tbl (rec.val) VALUES (NULL);
INSERT 0 1
postgres=# 
postgres=# CREATE LANGUAGE plpythonu;
CREATE LANGUAGE
postgres=# CREATE OR REPLACE FUNCTION trg() RETURNS trigger
postgres-# LANGUAGE plpythonu
postgres-# AS $$
postgres$# return 'MODIFY';
postgres$# $$;
CREATE FUNCTION
postgres=# 
postgres=# CREATE TRIGGER "!trg()"
postgres-# BEFORE INSERT OR UPDATE ON tbl
postgres-# FOR EACH ROW
postgres-# EXECUTE PROCEDURE trg();
CREATE TRIGGER
postgres=# 
postgres=# INSERT INTO tbl (val) VALUES (NULL);
INSERT 0 1
postgres=# 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"



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Reply via email to