[Haskell-cafe] handling NULL value in database query with Maybe (or other ...)
neil_mayhew at users.sourceforge.net
Tue Dec 18 15:22:44 UTC 2018
On 2018-12-18 7:43 AM, Damien Mattei wrote:
> i hoped asked could avoid using sort of Null pointer as mentioned in
> this article:
> if someone else have a simpler solution email me
You can avoid it: make the DNUM column non-NULL in your database schema.
That "worst mistake" applies to databases as well as programming
If you have to allow NULL in the database, then you have to handle
Nothing in your code. However, a neater way of doing it is to use the
forM_ bd_rows_WDS $ \(Only x) ->
putStrLn $ "x =" ++ maybe "" Text.unpack x
This allows you to provide a default value in your code for when the
column is NULL.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe