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

Filter FieldName <-. [Nothing] not finding expected results #1473

Open
rampion opened this issue Feb 15, 2023 · 6 comments
Open

Filter FieldName <-. [Nothing] not finding expected results #1473

rampion opened this issue Feb 15, 2023 · 6 comments

Comments

@rampion
Copy link

rampion commented Feb 15, 2023

I'm running into some odd behaviour where the filter FieldName <-. [Just v, Nothing] finds rows where FieldName is either null or v, but FieldName <-. [Nothing] doesn't find any rows at all.

  _johnId <- insert $ Person "John Doe" $ Just 35
  _janeId <- insert $ Person "Jane Doe" Nothing

  selectList [] [] -- finds no one
  selectList [PersonAge <-. [Nothing, Just 35]] [] -- finds John and Jane
  selectList [PersonAge <-. [Just 35]] [] -- finds John
  selectList [PersonAge <-. [Nothing]] [] -- expected to find Jane, but finds no one

Here's a complete repro using sqlite, but I've also observed this in Postgres.

@Vlix
Copy link
Contributor

Vlix commented Mar 1, 2023

I see this is because selectList uses selectSourceRes, which uses getFiltsValues, which uses filterClauseHelper that gets a OrNullNo, so it won't make an OR column IS NULL extension.

I'm not sure if anything would break if that would be adjusted internally, but I do know that PersonAge ==. Nothing would work as you'd expect. So that's at least a workaround.

@rampion
Copy link
Author

rampion commented Mar 1, 2023

Yeah currently my workaround is

selectList
  [ case ages of
      [] -> PersonAge ==. Nothing
      _:_ -> PersonAge <-. Nothing : map Just ages
  ]
  []

@Vlix
Copy link
Contributor

Vlix commented Mar 3, 2023

If you always want the NULL values, I think you can just write it as:

selectList ([PersonAge ==. Nothing] ||. [PersonAge <-. map Just ages]) []

@rampion
Copy link
Author

rampion commented Mar 3, 2023

Yes, there are many workarounds to this surprising behaviour.

@parsonsmatt
Copy link
Collaborator

I agree that this should be fixed, fwiw

@Vlix
Copy link
Contributor

Vlix commented Mar 3, 2023

I agree that this should be fixed, fwiw

Would changing the OrNullNo to OrNullYes in selectList break things? 🤔

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

3 participants