• skip to sidebar
  • skip to search box

trainedmonkey

by Jim Winstead Jr.

joining activerecord with mysql 5

dhh committed a patch for activerecord to make it work with mysql 5 that was subsequently reverted because it broke things on postgres and sqlite.

obviously we’d like ruby on rails to work with mysql 5, but because there was no test case committed along with either of these changes, i don’t really know the root cause of the problem. dhh claims it is the changes that made mysql conform to the standard sql join syntax, but i can’t evaluate that because i can’t reproduce the problem.

any activerecord gurus want to point me in the right direction?

» Wednesday, September 13, 2006 @ 10:57am » code, work, mysql, ruby on rails, activerecord » 1 comment, add yours
« better out-of-the-box mysql support for ruby on rails • ripped-up roof »

Comments

The solution is not to use parentheses. The solution is to use SQL92 syntax for joins consistently.

In other words, instead of using SQL89 syntax like this:

SELECT ... FROM a, b, c WHERE ...conditions...

One should use SQL92 syntax like this:

SELECT ... FROM a JOIN b ON ...join condition... JOIN c ON ...join condition... WHERE ...non-join conditions...

All RDBMS implementations should support SQL92 joins, and it will eliminate the precedence problems with the new join semantics in MySQL 5.0.

The new semantics only cause problems when someone mixes SQL89 syntax with SQL92 syntax like this:

SELECT ... FROM a, b LEFT JOIN c ON ...join condition... WHERE ...conditions...

SQL92 syntax is better and has been standard for 14 years. But nearly everyone I see on newsgroups persists in using SQL89 syntax at every opportunity.

» Bill Karwin (link) » Wednesday, September 13, 2006 @ 2:02pm

Add a comment

Sorry, comments on this post are closed.

  • Home
  • About
  • Archive
  • Bookmarks
  • Photos
  • Projects
  • GitHub
  • @jimw@mefi.social

Dedicated to the public domain by Jim Winstead Jr.