Postgresql Intervals with Opaleye

Another opaleye question: What type should I use for the postgresql interval type? Thanks Riaan

On Sun, Dec 28, 2014 at 10:01:27PM -0800, info@rotnetix.com wrote:
Another opaleye question: What type should I use for the postgresql interval type?
It seems that postgresql-simple doesn't support the interval type so the first step would be to get it added there. Tom

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. On Tuesday, December 30, 2014 9:03:32 PM UTC+11, Tom Ellis wrote:
On Sun, Dec 28, 2014 at 10:01:27PM -0800, in...@rotnetix.com javascript: wrote:
Another opaleye question: What type should I use for the postgresql interval type?
It seems that postgresql-simple doesn't support the interval type so the first step would be to get it added there.
Tom _______________________________________________ Haskell-Cafe mailing list Haskel...@haskell.org javascript: http://www.haskell.org/mailman/listinfo/haskell-cafe

On Tue, Dec 30, 2014 at 04:59:29PM -0800, info@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

Got it kind of working, for some reason the interval type in my postgres instance does not correspond to the parser from kqr but i managed to implement a version that kind of works. More importantly the experience has been great for understanding how to do my own conversion types. Thanks for the help. On Saturday, January 3, 2015 9:53:31 PM UTC+11, Tom Ellis wrote:
That might be tricky... See https://github.com/lpsmith/postgresql-simple/pull/115, it seems
On Tue, Dec 30, 2014 at 04:59:29PM -0800, in...@rotnetix.com javascript: wrote: 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 _______________________________________________ Haskell-Cafe mailing list Haskel...@haskell.org javascript: http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (2)
-
info@rotnetix.com
-
Tom Ellis