当前位置:网站首页>Gbase 8C trigger (III)
Gbase 8C trigger (III)
2022-07-03 02:22:00 【Dazhuang twelve】
A trigger definition can also specify a Boolean WHEN Conditions , It will be tested to see if the trigger should be triggered . In row level triggers ,WHEN The condition can check the old column value of the row and / Or new column value ( Statement level triggers can also have WHEN Conditions , But this feature is not very useful for them ). In a BEFORE Trigger ,WHEN The condition is only calculated before the function is or will be executed , Therefore use WHEN There is no essential difference between the condition and the same condition tested at the beginning of the trigger function . however , In a AFTER Trigger ,WHEN The condition is only calculated after the row update occurs , And it determines whether an event is queued at the end of the statement to trigger the trigger . So when a AFTER Trigger WHEN Do not return to true time , There is no need to queue an event at the end of the statement , There is no need to take out the line again . If the trigger only triggers for a few rows , This can significantly speed up the modification of many line statements .INSTEAD OF Trigger does not support WHEN Conditions .
Usually , Row level BEFORE It is used to check or modify the data to be inserted or updated . for example , One BEFORE Triggers can be used to insert the current time into a timestamp In the column , Or check whether the two elements of the row are consistent . Row level AFTER Triggers are mostly used to propagate updates to other tables , Or check the consistency of other tables . The reason for this division of work is , One AFTER The trigger can be sure that it sees the final value of the row , And one BEFORE Triggers cannot , Because there may be others BEFORE Trigger triggers after it . If you don't know, let a trigger be BEFORE or AFTER, be BEFORE Form is more effective , Because the information about this operation does not need to be saved until the end of the statement .
If a trigger function executes SQL command , Then these commands may trigger the trigger again . This is the so-called cascade trigger . There is no direct limit on the number of cascaded layers . Cascading may lead to recursive calls to the same trigger . for example , One INSERT The trigger may execute a command to insert an extra row into the same table , This leads to INSERT The trigger is triggered again . So in this case , Trigger programmers should be responsible for avoiding infinite recursion .
When defining a trigger , You can specify parameters for it . The purpose of including parameters in the trigger definition is to allow different triggers with similar requirements to call the same function . for example , There may be a general trigger function , It requires two column names as parameters , One puts the current user and the other puts the current timestamp . When written correctly , This trigger function should be independent of the table it triggers . Therefore, the same function can be used on any table with appropriate columns INSERT event , One of the purposes of this is to automatically track the creation of records in a transaction table . If defined as a UPDATE trigger , It can also be used to track the latest update events .
Each programming language that supports triggers has its own way to make trigger input data available to trigger functions . This input data includes the type of trigger event ( Such as INSERT or UPDATE) And listed in CREATE TRIGGER Any parameter in . For a row level trigger , Input data also includes for INSERT and UPDATE Trigger NEW That's ok , and / Or for UPDATE and DELETE Trigger OLD That's ok .
default , Statement level triggers have no way to check a single row modified by a statement . however AFTER STATEMENT Triggers can request the creation of transformation tables to make the affected rowsets available to triggers .AFTER ROW Triggers can also request conversion tables , So that they can see all the changes in the table and the changes in the single row they are currently triggering . The method of checking the transformation table again depends on the programming language being used , But the typical method is
边栏推荐
- [shutter] shutter debugging (debugging fallback function | debug method of viewing variables in debugging | console information)
- 机器学习流程与方法
- Simple understanding of SVG
- Awk from entry to burial (1) awk first meeting
- require.context
- GBase 8c系统表-pg_aggregate
- 4. Classes and objects
- leetcode961. Find the elements repeated N times in the array with length 2n
- stm32F407-------IIC通讯协议
- 单词单词单词
猜你喜欢
4. 类和对象
easyPOI
[shutter] bottom navigation bar implementation (bottomnavigationbar bottom navigation bar | bottomnavigationbaritem navigation bar entry | pageview)
Awk from introduction to earth (0) overview of awk
stm32F407-------DMA
RestCloud ETL 跨库数据聚合运算
Detailed introduction to the usage of Nacos configuration center
通达OA 首页门户工作台
stm32F407-------IIC通讯协议
PyTorch 卷积网络正则化 DropBlock
随机推荐
[Yu Yue education] China Ocean University job search OMG reference
javeScript 0.1 + 0.2 == 0.3的问题
Awk from entry to burial (1) awk first meeting
The Sandbox阐释对元宇宙平台的愿景
Gbase 8C system table PG_ conversion
require.context
[Yu Yue education] reference materials of chemical experiment safety knowledge of University of science and technology of China
Kotlin middle process understanding and Practice (I)
[Yu Yue education] reference materials of love psychology of China University of mining and technology
苏世民:25条工作和生活原则
詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信
GBase 8c系统表-pg_attribute
GBase 8c 函数/存储过程定义
4. 类和对象
require. context
使用Go语言实现try{}catch{}finally
【ROS进阶篇】第六讲 ROS中的录制与回放(rosbag)
Create + register sub apps_ Define routes, global routes and sub routes
Apple releases MacOS 11.6.4 update: mainly security fixes
GBase 8c系统表-pg_auth_members