karamaan / karamaan-opaleye

Other
11 stars 7 forks source link

Subselect support in updates (etc) #66

Open bergmark opened 10 years ago

bergmark commented 10 years ago

I'd like to generate queries like this:

update users set last_post = (select id from posts where foo) where bar

As far as I can tell this isn't possible since the update only takes an ExprArr wires maybewires.

Any ideas how to accomplish this?

tomjaguarpaw commented 10 years ago

Good question. Currently Opaleye does not support this. I suppose to work around this you would currently have to read the values in before writing them out again.

I guess the update functions would need to take a QueryArr instead of an ExprArr to support this. Do you know what happens if the select returns more than one row? Does it fail at runtime?

bergmark commented 10 years ago
ERROR:  more than one row returned by a subquery used as an expression
tomjaguarpaw commented 10 years ago

OK, it will be very hard to do this in a typesafe way so maybe we should just accept less type safety here.