Skip to content

Commit 6aec2ca

Browse files
committed
Extract check for VALUES/row_alias syntax
The change to upserts (rails#51274) is causing an issue with Vitess, since it doesn't support the `row_alias` syntax added in MySQL 8.0.19. There is an ongoing work (vitessio/vitess#15510) to add that support and it is likely to be included into Vitess v20, but in the meantime it would be nice to have an ability to control that behavior in the existing apps.
1 parent 0f3465c commit 6aec2ca

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ def build_insert_sql(insert) # :nodoc:
643643

644644
# MySQL 8.0.19 replaces `VALUES(<expression>)` clauses with row and column alias names, see https://dev.mysql.com/worklog/task/?id=6312 .
645645
# then MySQL 8.0.20 deprecates the `VALUES(<expression>)` see https://dev.mysql.com/worklog/task/?id=13325 .
646-
if !mariadb? && database_version >= "8.0.19"
646+
if supports_insert_raw_alias_syntax?
647647
values_alias = quote_table_name("#{insert.model.table_name}_values")
648648
sql = +"INSERT #{insert.into} #{insert.values_list} AS #{values_alias}"
649649

@@ -894,6 +894,10 @@ def remove_index_for_alter(table_name, column_name = nil, **options)
894894
"DROP INDEX #{quote_column_name(index_name)}"
895895
end
896896

897+
def supports_insert_raw_alias_syntax?
898+
!mariadb? && database_version >= "8.0.19"
899+
end
900+
897901
def supports_rename_index?
898902
if mariadb?
899903
database_version >= "10.5.2"

0 commit comments

Comments
 (0)