[Haskell-cafe] Postgresql Intervals with Opaleye

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Sat Jan 3 10:53:23 UTC 2015


On Tue, Dec 30, 2014 at 04:59:29PM -0800, info at rotnetix.com wrote:
> That might be tricky... 
>  See https://github.com/lpsmith/postgresql-simple/pull/115, it seems like 
> it is not trivial to get the conversions to haskell types correct.
> 
> Look like I am back to native SQL for that one.  

As lpsmith says here

    https://github.com/lpsmith/postgresql-simple/pull/115#issuecomment-48754627

you can use the attached patch in your own code to get a conversion from
`interval` to `DiffTime`.  It will have a few strange corner cases but you
will probably find you never hit them.

Once you've done that you can make them suitable for Opaleye by writing

    data PGInterval

    instance QueryRunnerColumnDefault PGInterval DiffTime where
          queryRunnerColumnDefault = fieldQueryRunnerColumn

(you may have to import something from Opaleye.Internal.RunQuery).

Please let me know how you get on with that, if you try it.

Tom


More information about the Haskell-Cafe mailing list