It does. However, on PostgreSQL with the standard_conforming_strings
= on setting, or other databases that implement strings in accordance
with the SQL standard, it generates wrong results, since the standard
doesn't allow for escaping with backslashes. For example, your new
code will wrongly escape the following:
'a\' || a.b || ''
Here the \ in the first string doesn't escape the closing quote. So
your code will incorrectly change a.b to a_b.
In short, there isn't a simple way to parse SQL correctly with regular
expressions, as correct parsing depends not only on the database type
used, but also the specific database's configuration. This is the
reason Sequel never attempts to parse SQL.
Yeah, frankly this was only ever added to ease the migration to the
preloading code. Parsing sql or even guessing is a fools errand and
it's a never-ending tar-pit of special cases. Ideally by 3.1 we
remove this code and just error out if someone does
Model.include(:children).where("LOWER(children.name) = ?", something).
For those cases you can use joins() or somehow explicitly opt in. If
we had a do-over for 3.0, I'd go back and remove it then
Andrew, instead of extending our mad regexp, maybe the best way is
just to use .preload(:bars) not .include(:bars) for your case?