Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

postgresql, how to trigger a trigger function when only inserting successfully?

$
0
0

I set up a trigger for copying some fields of a new record to a new table when a new record is inserted. Anyway, that can successfully run. but my target is triggering when inserting successfully or completely, but now the trigger will be conducted whenever it is successful or failed.

I tried to find the solving in search engining, but I still struggling on this. So I pursue the solving here, thanks guys.

supplement:

for example:I reinsert the same record twice, but I set the "item" as the primary key, so the second time will not successfully insert. but the t2 still inserted by trigger.

trigger function:

BeginINSERT INTO t2 (item,attr_1)VALUES (New.item,New.attr_1);RETURN New;END;

Results Picture


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>