@@ -25,15 +25,12 @@ use serde::{Deserialize, Serialize};
2525use sqlparser_derive:: { Visit , VisitMut } ;
2626
2727use crate :: {
28- ast:: display_separated,
29- display_utils:: { indented_list , Indent , SpaceOrNewline } ,
28+ ast:: { display_separated} ,
29+ display_utils:: { Indent , SpaceOrNewline , indented_list } ,
3030} ;
3131
3232use super :: {
33- display_comma_separated, helpers:: attached_token:: AttachedToken , query:: InputFormatClause ,
34- Assignment , Expr , FromTable , Ident , InsertAliases , MysqlInsertPriority , ObjectName , OnInsert ,
35- OrderByExpr , Query , SelectInto , SelectItem , Setting , SqliteOnConflict , TableFactor ,
36- TableObject , TableWithJoins , UpdateTableFromKind , Values ,
33+ Assignment , Expr , FromTable , Ident , InsertAliases , MysqlInsertPriority , ObjectName , OnInsert , OptimizerHint , OrderByExpr , Query , SelectInto , SelectItem , Setting , SqliteOnConflict , TableFactor , TableObject , TableWithJoins , UpdateTableFromKind , Values , display_comma_separated, helpers:: attached_token:: AttachedToken , query:: InputFormatClause
3734} ;
3835
3936/// INSERT statement.
@@ -43,6 +40,11 @@ use super::{
4340pub struct Insert {
4441 /// Token for the `INSERT` keyword (or its substitutes)
4542 pub insert_token : AttachedToken ,
43+ /// A query optimizer hint
44+ ///
45+ /// [MySQL](https://dev.mysql.com/doc/refman/8.4/en/optimizer-hints.html)
46+ /// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Comments.html#GUID-D316D545-89E2-4D54-977F-FC97815CD62E)
47+ pub optimizer_hint : Option < OptimizerHint > ,
4648 /// Only for Sqlite
4749 pub or : Option < SqliteOnConflict > ,
4850 /// Only for mysql
@@ -102,7 +104,11 @@ impl Display for Insert {
102104 } ;
103105
104106 if let Some ( on_conflict) = self . or {
105- write ! ( f, "INSERT {on_conflict} INTO {table_name} " ) ?;
107+ f. write_str ( "INSERT" ) ?;
108+ if let Some ( hint) = self . optimizer_hint . as_ref ( ) {
109+ write ! ( f, " {hint}" ) ?;
110+ }
111+ write ! ( f, " {on_conflict} INTO {table_name} " ) ?;
106112 } else {
107113 write ! (
108114 f,
@@ -111,8 +117,10 @@ impl Display for Insert {
111117 "REPLACE"
112118 } else {
113119 "INSERT"
114- } ,
115- ) ?;
120+ } ) ?;
121+ if let Some ( hint) = self . optimizer_hint . as_ref ( ) {
122+ write ! ( f, " {hint}" ) ?;
123+ }
116124 if let Some ( priority) = self . priority {
117125 write ! ( f, " {priority}" , ) ?;
118126 }
0 commit comments