Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
37.2. Visibility of Data Changes
Prev UpChapter 37. TriggersHome Next

37.2. Visibility of Data Changes#

If you execute SQL commands in your trigger function, and these commands access the table that the trigger is for, then you need to be aware of the data visibility rules, because they determine whether these SQL commands will see the data change that the trigger is fired for. Briefly:

  • Statement-level triggers follow simple visibility rules: none of the changes made by a statement are visible to statement-levelBEFORE triggers, whereas all modifications are visible to statement-levelAFTER triggers.

  • The data change (insertion, update, or deletion) causing the trigger to fire is naturallynot visible to SQL commands executed in a row-levelBEFORE trigger, because it hasn't happened yet.

  • However, SQL commands executed in a row-levelBEFORE triggerwill see the effects of data changes for rows previously processed in the same outer command. This requires caution, since the ordering of these change events is not in general predictable; an SQL command that affects multiple rows can visit the rows in any order.

  • Similarly, a row-levelINSTEAD OF trigger will see the effects of data changes made by previous firings ofINSTEAD OF triggers in the same outer command.

  • When a row-levelAFTER trigger is fired, all data changes made by the outer command are already complete, and are visible to the invoked trigger function.

If your trigger function is written in any of the standard procedural languages, then the above statements apply only if the function is declaredVOLATILE. Functions that are declaredSTABLE orIMMUTABLE will not see changes made by the calling command in any case.

Further information about data visibility rules can be found inSection 45.5. The example inSection 37.4 contains a demonstration of these rules.


Prev Up Next
37.1. Overview of Trigger Behavior Home 37.3. Writing Trigger Functions in C
pdfepub
Go to PostgreSQL 17
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp