Generate non standard SQL? #111

Open
rolftimmermans opened this Issue Mar 16, 2012 · 2 comments

Comments

Projects
None yet
2 participants

I'm trying to generate two UPDATE queries that are functionally equivalent, but one is for MySQL and the other for PostgreSQL:

MySQL:

UPDATE a, (SELECT ...) b
SET a.foo = b.bar
WHERE a.id = b.id

PostgreSQL:

UPDATE a
SET a.foo = b.bar
FROM (SELECT ...) b
WHERE a.id = b.id

I'd like to generate these queries with Arel, because the conditions and updated columns are nontrivial. The MySQL version seems to be possible with some SqlLiteral hacking. I cannot figure out how to generate the PostgreSQL query, though, since there is no support for FROM in UPDATE statements.

If I wrote a patch to support FROM in UPDATE statements, would it be included in Arel? If not, is there a (supported) alternative way to use Arel to build non standard SQL queries like these? I'm trying to avoid having to do a lot of string manipulation. Thanks!

I need the FROM clause support. Do you have it in a fork of the project or as a monkey patch?

No, I haven't written any patch for Arel yet. I've fallen back to string manipulation for this part of the query for now, although I still aim to use Arel to generate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment