![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
CREATE TABLE category ( id INT PRIMARY KEY, name TEXT); CREATE TABLE category_todo ( cat_id INT REFERENCES category(id) DEFERRABLE INITIALLY DEFERRED ); BEGIN; INSERT INTO category (id, name) VALUES (0, 'test'); INSERT INTO category_todo (cat_id) VALUES (0); TRUNCATE category_todo; COMMIT; -- COMMIT fails with: 'failed to fetch new tuple for AFTER trigger' |
#3
| |||
| |||
|
|
Markus Schiltknecht <markus (AT) bluegap (DOT) ch> writes: CREATE TABLE category ( id INT PRIMARY KEY, name TEXT); CREATE TABLE category_todo ( cat_id INT REFERENCES category(id) DEFERRABLE INITIALLY DEFERRED ); BEGIN; INSERT INTO category (id, name) VALUES (0, 'test'); INSERT INTO category_todo (cat_id) VALUES (0); TRUNCATE category_todo; COMMIT; -- COMMIT fails with: 'failed to fetch new tuple for AFTER trigger' Hm. At least for this case, it seems the nicest behavior would be for TRUNCATE to scan the deferred-triggers list and just throw away any pending trigger firings for the target table(s). I wonder however whether there are cases where that would be a bad idea. It might be safer for the TRUNCATE to error out if there are any pending triggers. Stephan, any thoughts about it? |
#4
| |||
| |||
|
|
Yeah, I think there are a few possibilities around truncate inside a savepoint that's rolledback that we have to be careful of. |
|
If we could mark the entries in some way so we knew whether or not they were made obsolete by a truncate of our own tranasaction or a committed or rolled back past subtransaction of ours, we could probably make both of these work nicely. |
#5
| |||
| |||
|
|
Stephan Szabo <sszabo (AT) megazone (DOT) bigpanda.com> writes: Yeah, I think there are a few possibilities around truncate inside a savepoint that's rolledback that we have to be careful of. Yuck :-( If we could mark the entries in some way so we knew whether or not they were made obsolete by a truncate of our own tranasaction or a committed or rolled back past subtransaction of ours, we could probably make both of these work nicely. That seems much more trouble than it's worth, unless someone can convince me that this isn't a corner case with little real-world value. Furthermore, this still doesn't address the worry about whether there are cases where dropping the trigger calls would be inappropriate. |
|
I propose just having TRUNCATE check for pending triggers on the target tables, and throw an error if there are any. |
#6
| |||
| |||
|
|
Stephan Szabo <sszabo (AT) megazone (DOT) bigpanda.com> writes: Yeah, I think there are a few possibilities around truncate inside a savepoint that's rolledback that we have to be careful of. Yuck :-( If we could mark the entries in some way so we knew whether or not they were made obsolete by a truncate of our own tranasaction or a committed or rolled back past subtransaction of ours, we could probably make both of these work nicely. That seems much more trouble than it's worth, unless someone can convince me that this isn't a corner case with little real-world value. Furthermore, this still doesn't address the worry about whether there are cases where dropping the trigger calls would be inappropriate. I propose just having TRUNCATE check for pending triggers on the target tables, and throw an error if there are any. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match |
![]() |
| Thread Tools | |
| Display Modes | |
| |