@@ -2922,6 +2922,26 @@ impl Spanned for RenameTableNameKind {
29222922 }
29232923}
29242924
2925+ #[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
2926+ #[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
2927+ #[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
2928+ /// Whether the syntax used for the trigger object (ROW or STATEMENT) is `FOR` or `FOR EACH`.
2929+ pub enum TriggerObjectKind {
2930+ /// The `FOR` syntax is used.
2931+ For ( TriggerObject ) ,
2932+ /// The `FOR EACH` syntax is used.
2933+ ForEach ( TriggerObject ) ,
2934+ }
2935+
2936+ impl Display for TriggerObjectKind {
2937+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
2938+ match self {
2939+ TriggerObjectKind :: For ( obj) => write ! ( f, "FOR {obj}" ) ,
2940+ TriggerObjectKind :: ForEach ( obj) => write ! ( f, "FOR EACH {obj}" ) ,
2941+ }
2942+ }
2943+ }
2944+
29252945#[ derive( Debug , Clone , PartialEq , PartialOrd , Eq , Ord , Hash ) ]
29262946#[ cfg_attr( feature = "serde" , derive( Serialize , Deserialize ) ) ]
29272947#[ cfg_attr( feature = "visitor" , derive( Visit , VisitMut ) ) ]
@@ -2943,6 +2963,23 @@ pub struct CreateTrigger {
29432963 ///
29442964 /// [MsSql](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql?view=sql-server-ver16#arguments)
29452965 pub or_alter : bool ,
2966+ /// True if this is a temporary trigger.
2967+ ///
2968+ /// Examples:
2969+ ///
2970+ /// ```sql
2971+ /// CREATE TEMP TRIGGER trigger_name
2972+ /// ```
2973+ ///
2974+ /// or
2975+ ///
2976+ /// ```sql
2977+ /// CREATE TEMPORARY TRIGGER trigger_name;
2978+ /// CREATE TEMP TRIGGER trigger_name;
2979+ /// ```
2980+ ///
2981+ /// [SQLite](https://sqlite.org/lang_createtrigger.html#temp_triggers_on_non_temp_tables)
2982+ pub temporary : bool ,
29462983 /// The `OR REPLACE` clause is used to re-create the trigger if it already exists.
29472984 ///
29482985 /// Example:
@@ -2987,6 +3024,8 @@ pub struct CreateTrigger {
29873024 /// ```
29883025 pub period : TriggerPeriod ,
29893026 /// Whether the trigger period was specified before the target table name.
3027+ /// This does not refer to whether the period is BEFORE, AFTER, or INSTEAD OF,
3028+ /// but rather the position of the period clause in relation to the table name.
29903029 ///
29913030 /// ```sql
29923031 /// -- period_before_table == true: Postgres, MySQL, and standard SQL
@@ -3006,9 +3045,9 @@ pub struct CreateTrigger {
30063045 pub referencing : Vec < TriggerReferencing > ,
30073046 /// This specifies whether the trigger function should be fired once for
30083047 /// every row affected by the trigger event, or just once per SQL statement.
3009- pub trigger_object : TriggerObject ,
3010- /// Whether to include the `EACH` term of the `FOR EACH`, as it is optional syntax .
3011- pub include_each : bool ,
3048+ /// This is optional in some SQL dialects, such as SQLite, and if not specified, in
3049+ /// those cases, the implied default is `FOR EACH ROW` .
3050+ pub trigger_object : Option < TriggerObjectKind > ,
30123051 /// Triggering conditions
30133052 pub condition : Option < Expr > ,
30143053 /// Execute logic block
@@ -3025,6 +3064,7 @@ impl Display for CreateTrigger {
30253064 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
30263065 let CreateTrigger {
30273066 or_alter,
3067+ temporary,
30283068 or_replace,
30293069 is_constraint,
30303070 name,
@@ -3036,15 +3076,15 @@ impl Display for CreateTrigger {
30363076 referencing,
30373077 trigger_object,
30383078 condition,
3039- include_each,
30403079 exec_body,
30413080 statements_as,
30423081 statements,
30433082 characteristics,
30443083 } = self ;
30453084 write ! (
30463085 f,
3047- "CREATE {or_alter}{or_replace}{is_constraint}TRIGGER {name} " ,
3086+ "CREATE {temporary}{or_alter}{or_replace}{is_constraint}TRIGGER {name} " ,
3087+ temporary = if * temporary { "TEMPORARY " } else { "" } ,
30483088 or_alter = if * or_alter { "OR ALTER " } else { "" } ,
30493089 or_replace = if * or_replace { "OR REPLACE " } else { "" } ,
30503090 is_constraint = if * is_constraint { "CONSTRAINT " } else { "" } ,
@@ -3076,10 +3116,8 @@ impl Display for CreateTrigger {
30763116 write ! ( f, " REFERENCING {}" , display_separated( referencing, " " ) ) ?;
30773117 }
30783118
3079- if * include_each {
3080- write ! ( f, " FOR EACH {trigger_object}" ) ?;
3081- } else if exec_body. is_some ( ) {
3082- write ! ( f, " FOR {trigger_object}" ) ?;
3119+ if let Some ( trigger_object) = trigger_object {
3120+ write ! ( f, " {trigger_object}" ) ?;
30833121 }
30843122 if let Some ( condition) = condition {
30853123 write ! ( f, " WHEN {condition}" ) ?;
0 commit comments