yesodweb/yesod — Issue #175: Persistent !=. queries against non-nullable columns seem to be broken 
Author: maxcan
Created: 2011-11-24 03:28:56+00:00
State: open

I have an ADT: MsgState = MsgNew | MsgDelivered | MsgRead for which I use the derivePersistField TH function to derive the persist field instance.

And a table:
Msg
state MsgState
body Text

Queries like
selectList [MsgState !=. MsgRead] []

return [] even though they should be returning values. The reason is that the query persistent-postgresql generates looks for values where state is NULL instead of just not equal to what we want.

from my query log:
SELECT id,"body", "state" FROM "Message" WHERE ("state" IS NULL)

The workaround is to use the not-member operator as follows:
selectList [MsgState /<-. [MsgRead]] []