@@ -152,6 +152,10 @@ public SqlNode getTargetTable() {
152152 return targetTable ;
153153 }
154154
155+ public void setTargetTable (SqlNode targetTable ) {
156+ this .targetTable = targetTable ;
157+ }
158+
155159 /** Returns the alias for the target table of this UPDATE. */
156160 @ Pure
157161 public @ Nullable SqlIdentifier getAlias () {
@@ -186,6 +190,10 @@ public SqlNodeList getAliases() {
186190 return aliases ;
187191 }
188192
193+ public void setAliases (SqlNodeList aliases ) {
194+ this .aliases = aliases ;
195+ }
196+
189197 public boolean singleTable () {
190198 return getSourceTables ().size () <= 1 ;
191199 }
@@ -228,11 +236,25 @@ public void setSourceSelect(SqlSelect sourceSelect) {
228236 writer .startList (SqlWriter .FrameTypeEnum .SELECT , "UPDATE" , "" );
229237 final int opLeft = getOperator ().getLeftPrec ();
230238 final int opRight = getOperator ().getRightPrec ();
231- targetTable .unparse (writer , opLeft , opRight );
232- SqlIdentifier alias = this .alias ;
233- if (alias != null ) {
234- writer .keyword ("AS" );
235- alias .unparse (writer , opLeft , opRight );
239+ if (singleTable ()) {
240+ targetTable .unparse (writer , opLeft , opRight );
241+ if (alias != null ) {
242+ writer .keyword ("AS" );
243+ alias .unparse (writer , opLeft , opRight );
244+ }
245+ } else {
246+ for (SqlNode table : sourceTables ) {
247+ if (table instanceof SqlIdentifier ) {
248+ ((SqlIdentifier ) table ).unparse (writer , opLeft , opRight );
249+ } else {
250+ table .unparse (writer , opLeft , opRight );
251+ }
252+ writer .keyword ("AS" );
253+ SqlIdentifier alias = (SqlIdentifier ) aliases .get (sourceTables .indexOf (table ));
254+ alias .unparse (writer , opLeft , opRight );
255+ writer .sep ("," );
256+ }
257+ // targetTable.unparse(writer, opLeft, opRight);
236258 }
237259 final SqlWriter .Frame setFrame =
238260 writer .startList (SqlWriter .FrameTypeEnum .UPDATE_SET_LIST , "SET" , "" );
0 commit comments