@@ -33,7 +33,8 @@ use super::{
3333 display_comma_separated, helpers:: attached_token:: AttachedToken , query:: InputFormatClause ,
3434 Assignment , Expr , FromTable , Ident , InsertAliases , MysqlInsertPriority , ObjectName , OnInsert ,
3535 OptimizerHint , OrderByExpr , Query , SelectInto , SelectItem , Setting , SqliteOnConflict ,
36- TableFactor , TableObject , TableWithJoins , UpdateTableFromKind , Values ,
36+ TableAliasWithoutColumns , TableFactor , TableObject , TableWithJoins , UpdateTableFromKind ,
37+ Values ,
3738} ;
3839
3940/// INSERT statement.
@@ -56,8 +57,9 @@ pub struct Insert {
5657 pub into : bool ,
5758 /// TABLE
5859 pub table : TableObject ,
59- /// table_name as foo (for PostgreSQL)
60- pub table_alias : Option < Ident > ,
60+ /// `table_name as foo` (for PostgreSQL)
61+ /// `table_name foo` (for Oracle)
62+ pub table_alias : Option < TableAliasWithoutColumns > ,
6163 /// COLUMNS
6264 pub columns : Vec < Ident > ,
6365 /// Overwrite (Hive)
@@ -125,8 +127,13 @@ pub struct Insert {
125127impl Display for Insert {
126128 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
127129 // SQLite OR conflict has a special format: INSERT OR ... INTO table_name
128- let table_name = if let Some ( alias) = & self . table_alias {
129- format ! ( "{0} AS {alias}" , self . table)
130+ let table_name = if let Some ( table_alias) = & self . table_alias {
131+ format ! (
132+ "{table} {as_keyword}{alias}" ,
133+ table = self . table,
134+ as_keyword = if table_alias. explicit { "AS " } else { "" } ,
135+ alias = table_alias. alias
136+ )
130137 } else {
131138 self . table . to_string ( )
132139 } ;
0 commit comments