Commit 9eefae69 authored by Yorick Peterse's avatar Yorick Peterse

Fix UNION syntax for MySQL

Apparently MySQL doesn't support this syntax:

    (...) UNION (...)

instead it only supports:

    ...
    UNION
    ...
parent cc11c44b
...@@ -23,11 +23,11 @@ module Gitlab ...@@ -23,11 +23,11 @@ module Gitlab
# (thus fixing this problem), at a slight performance cost. # (thus fixing this problem), at a slight performance cost.
fragments = ActiveRecord::Base.connection.unprepared_statement do fragments = ActiveRecord::Base.connection.unprepared_statement do
@relations.map do |rel| @relations.map do |rel|
"(#{rel.reorder(nil).to_sql})" rel.reorder(nil).to_sql
end end
end end
fragments.join(' UNION ') fragments.join("\nUNION\n")
end end
end end
end end
......
...@@ -10,7 +10,7 @@ describe Gitlab::SQL::Union do ...@@ -10,7 +10,7 @@ describe Gitlab::SQL::Union do
sql1 = rel1.reorder(nil).to_sql sql1 = rel1.reorder(nil).to_sql
sql2 = rel2.reorder(nil).to_sql sql2 = rel2.reorder(nil).to_sql
expect(union.to_sql).to eq("(#{sql1}) UNION (#{sql2})") expect(union.to_sql).to eq("#{sql1}\nUNION\n#{sql2}")
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment