I'm using PostgresSQL and I wanted to update a column to the default value if it was NULL.
Beam happily accepts both
(\r -> coalesce_ [just_ $current_ r.column] default_)
and
(\r -> if_ [isNothing_ (current_ r.column) then_ default_] (else_ $ current_ r.column))
But coalesce(r.column,DEFAULT) is not valid sql.
I need to supply the default manually.
I didn't find the proper way for this in beam, as the default is current_timestamp but the column is timstamptz in postgres corresponding to UTCTime in Haskell, but now_ in Beam only works for LocalTime .
I got around it with using coerce_ now_ instead,
but this doesn't feel right as it seems that GHC will happily coerce ANY beam type to one another...
(I have also used this coerce trick to get out of Maybe/Nullable when selecting only not null rows, haven't found a good way for this either.)
I'm using PostgresSQL and I wanted to update a column to the default value if it was NULL.
Beam happily accepts both
(\r -> coalesce_ [just_ $current_ r.column] default_)and
(\r -> if_ [isNothing_ (current_ r.column)then_default_] (else_ $ current_ r.column))But
coalesce(r.column,DEFAULT)is not valid sql.I need to supply the default manually.
I didn't find the proper way for this in beam, as the default is
current_timestampbut the column istimstamptzin postgres corresponding toUTCTimein Haskell, butnow_in Beam only works forLocalTime.I got around it with using
coerce_ now_instead,but this doesn't feel right as it seems that GHC will happily coerce ANY beam type to one another...
(I have also used this coerce trick to get out of Maybe/Nullable when selecting only not null rows, haven't found a good way for this either.)