Skip to content

Commit

Permalink
Extract check for VALUES/row_alias syntax
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
maxprokopiev committed Mar 19, 2024
1 parent 0f3465c commit 6aec2ca
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def build_insert_sql(insert) # :nodoc:

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

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

def supports_insert_raw_alias_syntax?
!mariadb? && database_version >= "8.0.19"
end

def supports_rename_index?
if mariadb?
database_version >= "10.5.2"
Expand Down

0 comments on commit 6aec2ca

Please sign in to comment.