Skip to content
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

Natural/Composite key and IN (<-.) operator returning wrong results #1558

Open
eddiemundo opened this issue Nov 1, 2024 · 0 comments
Open

Comments

@eddiemundo
Copy link

eddiemundo commented Nov 1, 2024

share
  [mkPersist sqlSettings, mkMigrate "migrateAll"]
  [persistLowerCase|
Person
    tid Text
    index Word
    age Int Maybe
    Primary tid index
    deriving Show
  |]

action :: ReaderT SqlBackend (NoLoggingT (ResourceT IO)) ()
action = do
  deleteWhere ([] :: [Filter Person])

  _ <- insert $ Person "tid1" 0 (Just 10)
  _ <- insert $ Person "tid1" 1 (Just 11)

  hmm <- selectList [PersonId <-. [PersonKey "tid1" 0, PersonKey "tid2" 1]] []

  liftIO $ print hmm

returns

[Entity {entityKey = PersonKey {personKeytid = "tid1", personKeyindex = 0}, entityVal = Person {personTid = "tid1", personIndex = 0, personAge = Just 10}},Entity {entityKey = PersonKey {personKeytid = "tid1", personKeyindex = 1}, entityVal = Person {personTid = "tid1", personIndex = 1, personAge = Just 11}}]

It should only return ("tid1", 0). Interestingly if I filter using

[PersonKey "tidlasdjflajsd1" 0, PersonKey "tid2" 1]

It returns []

It was deleting rows for mysterious reasons, and pretty broken, unless my intuition about (<-.) and filters is completely wrong. I thought it would translate to where (tid, index) IN (('tid1', 0), ('tid2', 1)). A workaround seems to be FilterOr a list of ==.?

I figured out how to get the SQL being used

SELECT "tid", "index", "age" FROM "person" WHERE ((("tid" IN ( ?, ?) ) and ("index" IN ( ?, ?) ))); [PersistText "tid1",PersistText "tid2",PersistInt64 0,PersistInt64 1]

so definitely not what I expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant