I've got a SQL query in Postgres that works fine from a SQL console/tool, but not through Rails' ActiveRecord (ActiveRecord::Base.connection.execute/select_all). I've tried a bunch of stuff like escaping quotes, calling ActiveRecord::Base.quote/sanitize to no avail - ActiveRecord returns an empty set where I've verified a tuple gets returned with this query.
SELECT
... blah blah
FROM
... joins joins joins
inner join core.pat_assignments assignment on assignment.correspondent_alias_id = out_alias.id
inner join core.pats patent on patent.id = assignment.pat_id and (select regexp_matches(patent.us_class_current, '(\w+)\/')) = '{D02}'
where
in_alias.id in (1987, 5004)
The funny thing is, it returns something if I take out the last inner join line, specifically the regex match. So there's something with:
(select regexp_matches(patent.us_class_current, '(\w+)\/')) = '{D02}'
that's making it throw up, but I just can't figure out why... any suggestions would be greatly appreciated!