pub struct CreateTrigger {Show 17 fields
pub or_alter: bool,
pub or_replace: bool,
pub is_constraint: bool,
pub name: ObjectName,
pub period: TriggerPeriod,
pub period_before_table: bool,
pub events: Vec<TriggerEvent>,
pub table_name: ObjectName,
pub referenced_table_name: Option<ObjectName>,
pub referencing: Vec<TriggerReferencing>,
pub trigger_object: TriggerObject,
pub include_each: bool,
pub condition: Option<Expr>,
pub exec_body: Option<TriggerExecBody>,
pub statements_as: bool,
pub statements: Option<ConditionalStatements>,
pub characteristics: Option<ConstraintCharacteristics>,
}Expand description
CREATE TRIGGER
Examples:
CREATE TRIGGER trigger_name
BEFORE INSERT ON table_name
FOR EACH ROW
EXECUTE FUNCTION trigger_function();Postgres: https://www.postgresql.org/docs/current/sql-createtrigger.html SQL Server: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql
Fields§
§or_alter: boolTrue if this is a CREATE OR ALTER TRIGGER statement
or_replace: boolThe OR REPLACE clause is used to re-create the trigger if it already exists.
Example:
CREATE OR REPLACE TRIGGER trigger_name
AFTER INSERT ON table_name
FOR EACH ROW
EXECUTE FUNCTION trigger_function();is_constraint: boolThe CONSTRAINT keyword is used to create a trigger as a constraint.
name: ObjectNameThe name of the trigger to be created.
period: TriggerPeriodDetermines whether the function is called before, after, or instead of the event.
Example of BEFORE:
CREATE TRIGGER trigger_name
BEFORE INSERT ON table_name
FOR EACH ROW
EXECUTE FUNCTION trigger_function();Example of AFTER:
CREATE TRIGGER trigger_name
AFTER INSERT ON table_name
FOR EACH ROW
EXECUTE FUNCTION trigger_function();Example of INSTEAD OF:
CREATE TRIGGER trigger_name
INSTEAD OF INSERT ON table_name
FOR EACH ROW
EXECUTE FUNCTION trigger_function();period_before_table: boolWhether the trigger period was specified before the target table name.
-- period_before_table == true: Postgres, MySQL, and standard SQL
CREATE TRIGGER t BEFORE INSERT ON table_name ...;
-- period_before_table == false: MSSQL
CREATE TRIGGER t ON table_name BEFORE INSERT ...;events: Vec<TriggerEvent>Multiple events can be specified using OR, such as INSERT, UPDATE, DELETE, or TRUNCATE.
table_name: ObjectNameThe table on which the trigger is to be created.
referenced_table_name: Option<ObjectName>The optional referenced table name that can be referenced via
the FROM keyword.
referencing: Vec<TriggerReferencing>This keyword immediately precedes the declaration of one or two relation names that provide access to the transition relations of the triggering statement.
trigger_object: TriggerObjectThis specifies whether the trigger function should be fired once for every row affected by the trigger event, or just once per SQL statement.
include_each: boolWhether to include the EACH term of the FOR EACH, as it is optional syntax.
condition: Option<Expr>Triggering conditions
exec_body: Option<TriggerExecBody>Execute logic block
statements_as: boolFor MSSQL and dialects where statements are preceded by AS
statements: Option<ConditionalStatements>For SQL dialects with statement(s) for a body
characteristics: Option<ConstraintCharacteristics>The characteristic of the trigger, which include whether the trigger is DEFERRABLE, INITIALLY DEFERRED, or INITIALLY IMMEDIATE,
Trait Implementations§
Source§impl Clone for CreateTrigger
impl Clone for CreateTrigger
Source§fn clone(&self) -> CreateTrigger
fn clone(&self) -> CreateTrigger
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more