This is an attempt to check unique constraints in a graph of inheritance by
means of a trigger. The trigger is written in plpython
and is relatively slow
(> 50 ms by insert or update).
THE TRIGGER DOESN'T WORK WITH UPDATE... It would require to count if more than one row is updated by the query and, in that case, if any attribute of a unique constraint is modified (new != old). If anyone can see a way to do this, let me know.
If you can insure that only one row is modified at a time, the trigger should work.
The database structure used to test the trigger.- The trigger requires psycopg2 Python module.
- You must use
create language plpythonu;
to use the trigger. - Have a look at
tables.sql
to see how to use the trigger. - I have tested it with both
plpython3u
andplpythonu
and it seems to be a little faster withplpythonu
. If you want to use it withplpython3u
, just replaceplpythonu
byplpython3u
at the end ofcheck_unicity_trigger.sql
.
WARNING! The test.sh
shell program drops and recreates a database
named oopg (who knows ;).
Keywords: postgresql
, inheritance
, plpython
, trigger