-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What does Rebind do in optionalRestrict
?
#546
Comments
That sounds strange. Did you replace your left join using this pattern? When there are missing rows in the right query you are supposed to get proc () -> do
fieldsL <- qL -< ()
maybeFieldsR <- optionalRestrict qR -< curry cond fieldsL
returnA -< (fieldsL, maybeFieldsR) |
Here's an example. The output is
{-# LANGUAGE Arrows #-}
module Main where
import Control.Arrow (returnA)
import Opaleye
import qualified Database.Postgres.Temp as T
import qualified Database.PostgreSQL.Simple as S
import qualified Database.PostgreSQL.Simple.Options as O
import GHC.IO.Exception (ExitCode)
qL = values [(1, 10), (2, 20)]
qR = values [(2, toFields "Hello"), (3, toFields "Good bye")]
exampleJoin :: Select ((Field SqlInt4, Field SqlInt4),
MaybeFields (Field SqlInt4, Field SqlText))
exampleJoin = proc () -> do
fieldsL@(x, t) <- qL -< ()
maybeFieldsR <- optionalRestrict qR -< (\(y, s) -> x .== y)
returnA -< (fieldsL, maybeFieldsR)
run = withTempDBConnection $ \conn ->
print =<< runSelectI conn exampleJoin
withTempDBConnection :: (S.Connection -> IO a)
-> IO (Either T.StartError a)
withTempDBConnection f = T.with $ \tempDB ->
f =<< S.connectPostgreSQL (T.toConnectionString tempDB) |
Sorry @tomjaguarpaw , it's not |
I'm trying to refactor all my
leftJoin
s to useoptionalRestrict
based on the docsIt compiles well but the query behaves differently.
when right query returns nothing, and left query returns something,
leftJoin
would still return rows with fields that come from right querynull
. ButoptionalRestrict
would just return empty rows.In the generated SQL, I see a rebind always true in the right table. Removing that and in the
where
it works as expected. I can't figure out what rebind does here. I believe simple code example like the one in the docs can replicate the problem but let me know if not. Thanks.The text was updated successfully, but these errors were encountered: