当前位置:网站首页>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
边栏推荐
- Qt之QComboBox添加QCheckBox(下拉列表框插入复选框,含源码+注释)
- Gbase 8C system table PG_ authid
- Awk from introduction to earth (0) overview of awk
- Deep learning notes (constantly updating...)
- Wechat applet development tool post net:: err_ PROXY_ CONNECTION_ Failed agent problem
- Exception handling in kotlin process
- GBase 8c系统表-pg_constraint
- Detailed introduction to the usage of Nacos configuration center
- 4. 类和对象
- GBase 8c系统表pg_cast
猜你喜欢

easyExcel

Thread safe singleton mode

面试项目技术栈总结

Awk from introduction to earth (0) overview of awk

Recommendation letter of "listing situation" -- courage is the most valuable

The use of Flink CDC mongodb and the implementation of Flink SQL parsing complex nested JSON data in monggo

Flink CDC mongoDB 使用及Flink sql解析monggo中复杂嵌套JSON数据实现

Producer consumer model based on thread pool (including blocking queue)

詳細些介紹如何通過MQTT協議和華為雲物聯網進行通信

8 free, HD, copyright free video material download websites are recommended
随机推荐
GBase 8c触发器(二)
Tongda OA V12 process center
GBase 8c系统表-pg_collation
JS的装箱和拆箱
Wechat applet development tool post net:: err_ PROXY_ CONNECTION_ Failed agent problem
stm32F407-------DMA
CFdiv2-Fixed Point Guessing-(區間答案二分)
单词单词单词
Simple understanding of SVG
Recommendation letter of "listing situation" -- courage is the most valuable
[Yu Yue education] reference materials of love psychology of China University of mining and technology
Gbase 8C system table PG_ class
[tutorial] chrome turns off cross domain policies CORS and samesite, and brings cookies across domains
The Sandbox阐释对元宇宙平台的愿景
[Yu Yue education] reference materials of chemical experiment safety knowledge of University of science and technology of China
Kotlin middle process understanding and Practice (II)
CFdiv2-Fixed Point Guessing-(区间答案二分)
Awk from getting started to being buried (2) understand the built-in variables and the use of variables in awk
What are the key points often asked in the redis interview
Socket编程