pl/python invalidate functions with composite arguments
Jan Urbański <wulczer@wulczer.org>
From: Jan Urbański <wulczer@wulczer.org>
To: Postgres - Hackers <pgsql-hackers@postgresql.org>
Date: 2010-12-23T13:50:46Z
Lists: pgsql-hackers
Attachments
- plpython-invalidate-composites.diff (text/x-patch) patch
Here's a patch implementing properly invalidating functions that have
composite type arguments after the type changes, as mentioned in
http://archives.postgresql.org/pgsql-hackers/2010-12/msg01991.php. It's
an incremental patch on top of the plpython-refactor patch sent eariler.
Git branch for this patch:
https://github.com/wulczer/postgres/tree/invalidate-composites.
The idea in general is for this to work (taken straight from the unit
tests, btw)
CREATE TABLE employee (
name text,
basesalary integer,
bonus integer
);
INSERT INTO employee VALUES ('John', 100, 10), ('Mary', 200, 10);
CREATE OR REPLACE FUNCTION test_composite_table_input(e employee)
RETURNS integer AS $$
return e['basesalary'] + e['bonus']
$$ LANGUAGE plpythonu;
SELECT name, test_composite_table_input(employee.*) FROM employee;
ALTER TABLE employee DROP bonus;
-- this fails
SELECT name, test_composite_table_input(employee.*) FROM employee;
ALTER TABLE employee ADD bonus integer;
UPDATE employee SET bonus = 10;
-- this works again
SELECT name, test_composite_table_input(employee.*) FROM employee;
It's a long-standing TODO item, and a generally good thing to do.
Cheers,
Jan