File tree Expand file tree Collapse file tree 2 files changed +44
-10
lines changed
src/query/sql/src/planner/binder
tests/sqllogictests/suites/base/09_fuse_engine Expand file tree Collapse file tree 2 files changed +44
-10
lines changed Original file line number Diff line number Diff line change @@ -365,13 +365,28 @@ impl Binder {
365
365
columns_set = columns_set. union ( & join_column_set) . cloned ( ) . collect ( ) ;
366
366
}
367
367
368
+ // If the table alias is not None, after the binding phase, the bound columns will have
369
+ // a database of 'None' and the table named as the alias.
370
+ // Thus, we adjust them accordingly.
371
+ let target_name = if let Some ( target_identify) = target_alias {
372
+ normalize_identifier ( & target_identify. name , & self . name_resolution_ctx )
373
+ . name
374
+ . clone ( )
375
+ } else {
376
+ table_name. clone ( )
377
+ } ;
378
+
368
379
let has_update = self . has_update ( & matched_clauses) ;
369
380
let update_row_version = if table. change_tracking_enabled ( ) && has_update {
370
381
Some ( Self :: update_row_version (
371
382
table. schema_with_stream ( ) ,
372
383
& bind_ctx. columns ,
373
- Some ( & database_name) ,
374
- Some ( & table_name) ,
384
+ if target_alias. is_none ( ) {
385
+ Some ( & database_name)
386
+ } else {
387
+ None
388
+ } ,
389
+ Some ( & target_name) ,
375
390
) ?)
376
391
} else {
377
392
None
@@ -400,14 +415,6 @@ impl Binder {
400
415
}
401
416
}
402
417
403
- let target_name = if let Some ( target_identify) = target_alias {
404
- normalize_identifier ( & target_identify. name , & self . name_resolution_ctx )
405
- . name
406
- . clone ( )
407
- } else {
408
- table_name. clone ( )
409
- } ;
410
-
411
418
// bind matched clause columns and add update fields and exprs
412
419
for clause in & matched_clauses {
413
420
matched_evaluators. push (
Original file line number Diff line number Diff line change @@ -195,6 +195,33 @@ drop table t3 all
195
195
# end of issue 14955 #
196
196
######################
197
197
198
+ ###############
199
+ # issue 15412 #
200
+ ###############
201
+
202
+ statement ok
203
+ CREATE TABLE test_select (id Int64, name STRING) change_tracking = true
204
+
205
+ statement ok
206
+ insert into test_select values(1, 'Wu')
207
+
208
+ query I
209
+ merge into db1.test_select t1 using (select * from db1.test_select) t2 on t1.id = t2.id when matched then update set t1.id=t2.id, t1.name='{}'
210
+ ----
211
+ 1
212
+
213
+ query ITI
214
+ select id, name, _row_version from test_select
215
+ ----
216
+ 1 {} 1
217
+
218
+ statement ok
219
+ drop table test_select all
220
+
221
+ ######################
222
+ # end of issue 15412 #
223
+ ######################
224
+
198
225
statement ok
199
226
set enable_experimental_merge_into = 0
200
227
You can’t perform that action at this time.
0 commit comments