On Sat, Sep 27, 2014 at 6:22 PM, Shai Berger <s...@platonix.com> wrote: > Upon reading the docs, I was a little surprised to see that in terms of > triggers etc, the operation is always considered an INSERT. I would expect it > to be considered an insert for BEFORE INSERT or INSTEAD OF INSERT triggers, > but if conflict resolution turns it into an UPDATE, I'd expect to see it > handled as an UPDATE from that point on (definitely INSTEAD OF UPDATE and > AFTER > UPDATE triggers, maybe even BEFORE UPDATE). That is the semantics we have now > (this is a general remark, not particulary Django-oriented; Django does not > use triggers on PG as far as I know, and only uses them elsewhere to implement > serial keys). > > Could you explain the reasoning behind the described behavior?
per-row BEFORE triggers from insert will fire even when we go to update (but not AFTER triggers from INSERT). We need to know what we're actually inserting before inserting/deciding to update. So BEFORE triggers must fire, because in principle (and, indeed, typically), they do modify the tuple being inserted. At the same time, that's user-defined code often entirely outside our ability to nullify. The statement-level trigger stuff (i.e. the idea that ON CONFLICT UPDATE never fires an UPDATE statement level trigger) is for consistency with user-defined rules, where we're really compelled to have INSERT...ON CONFLICT UPDATE just be seen as an UPDATE. But I admit that that isn't a very satisfactory state of affairs for people who are using per-statement triggers for auditing and things like that, and I wouldn't be surprised if that was revised. -- Peter Geoghegan -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAM3SWZS89AL2afHEOT2nn6B46OokpzoHs0HW5--GFLXQkUJY0A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.