| From: | Jan Urbański <wulczer(at)wulczer(dot)org> |
|---|---|
| To: | Postgres - Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | pl/python invalidate functions with composite arguments |
| Date: | 2010-12-23 13:50:46 |
| Message-ID: | 4D1353B6.1050806@wulczer.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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
| Attachment | Content-Type | Size |
|---|---|---|
| plpython-invalidate-composites.diff | text/x-patch | 10.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Jan Urbański | 2010-12-23 13:56:03 | pl/python tracebacks |
| Previous Message | Jan Urbański | 2010-12-23 13:45:28 | pl/python SPI in subtransactions |