On 02.06.2015 16:20, Melvin Davidson
wrote:
I think, I must explain the problem deeper: I have two (or more) tables CREATE TABLE a (id ... UNIQUE -- maby the PRIMARY KEY,...); CREATE TABLE b (...) INHERIT (a); But the id has to be unique over the inheritance. So one solution of the problem is: CREATE key_table (id ... UNIQUE, table REGCLASS); By trigger every INSERT/UPDATE/DELETE in Table a,b,... changes the key_table. This works. Now I have a table reference to the id of table a*. This is not possible, but reference to key_table(id) works fine. CREATE TABLE r (..., a_id /* REFERENCES a*(id) */ REFERENCES key_tabel(id),..); And now the problem: Can I support TRUNCATE TABLE? DELETE is not a problem: for DELETE FROM a the trigger deletes the entry in the key_table and if the reference action on delete is CASCADE, the entries in r will be deletet. But TRUNCATE TABLE a! In a TRUNCATE TRIGGER I can delete the entries in the key_table "WHERE table = a" (O.K. the performance) -- it is actual not a TRUNCATE TABLE but a TRUNCATE PARTITION. And if I not specified ONLY, there is also a TRUNCATE TABLE b and the trigger ist fired too. But what is with table r? If I do the delete in the key_table, the delete action will be used. But there is not a truncate action, cascaded truncation is controlled by execute TRUNCATE. And so, I must delete the entries in r if there is a CASCADE in the TRUNCATE or raise an exception if the TRUNCATE is RESTRICTED. Now the Question? How to find out in the trigger function for truncate whether is there a CASCADE or not. regards, Andreas
|