You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's actually a reason for that: you can't really blindly convert months to days, or days to hours/minutes/seconds, without further context regarding the specific time and location you are talking about.
Basically, NominalDiffTime is a proper subset of postgresql's interval type (modulo precision and range issues), and interval is a strict superset of NominalDiffTime.
That said, I have considered adding a FromField NominalDiffTime instance that assumes any intervals can be converted to seconds directly; any intervals that contain non-convertible components would result in an exception.
My apologies for forgetting to respond to this issue.
I guess, what's your goal here? If all you care about is storing NominalDiffTimes, and getting them back out with full fidelity, and you don't care about the semantics or having postgresql perform computations on them server-side, then you would have a few options. However, these options probably would not be a good fit for inclusion in vanilla postgresql-simple.
If you care about semantic similarity, which is the primary goal of vanilla postgresql-simple, then what option is there other than interval? A postgresql interval corresponds to data Interval = Interval { months :: Int32, days :: Int32, microseconds :: Int64 }, whereas a NominalDiffTime is an Integer of picoseconds. So, there's a lot of overlap, and NominalDiffTime is almost a subset of interval, but each type can represent some values the other can't.
I've also noticed that you don't have instances for Data.Fixed, is there a reason for that too?
@lpsmith Is there any reason not to include your Interval ADT in this library with the appropriate ToField/FromField conversions? It sounds like that's a pretty safe addition from a correctness perspective and it would allow first-class two-way conversion of Intervals <-> Haskells.
In addition, I would probably accept a pull request that adds a FromField instance for NominalDiffTime, as well as Fixed.
Though I may have looked into supporting Fixed once, and was a bit scared off by some unfortunate ways postgres's numeric type works. My memory is a bit fuzzy on that count.
Activity
lpsmith commentedon Feb 8, 2016
There's actually a reason for that: you can't really blindly convert months to days, or days to hours/minutes/seconds, without further context regarding the specific time and location you are talking about.
Basically,
NominalDiffTimeis a proper subset of postgresql'sintervaltype (modulo precision and range issues), andintervalis a strict superset ofNominalDiffTime.lpsmith commentedon Feb 8, 2016
That said, I have considered adding a
FromField NominalDiffTimeinstance that assumes any intervals can be converted to seconds directly; any intervals that contain non-convertible components would result in an exception.fizruk commentedon Feb 9, 2016
Hmm, maybe
intervalis not the right field type forNominalDiffTimetime then?I've also noticed that you don't have instances for
Data.Fixed, is there a reason for that too?If not, I could use
ToField/FromFieldinstances ofPicoto storeNominalDiffTime.lpsmith commentedon Mar 15, 2016
My apologies for forgetting to respond to this issue.
I guess, what's your goal here? If all you care about is storing
NominalDiffTimes, and getting them back out with full fidelity, and you don't care about the semantics or having postgresql perform computations on them server-side, then you would have a few options. However, these options probably would not be a good fit for inclusion in vanilla postgresql-simple.If you care about semantic similarity, which is the primary goal of vanilla postgresql-simple, then what option is there other than
interval? A postgresql interval corresponds todata Interval = Interval { months :: Int32, days :: Int32, microseconds :: Int64 }, whereas aNominalDiffTimeis anIntegerof picoseconds. So, there's a lot of overlap, andNominalDiffTimeis almost a subset ofinterval, but each type can represent some values the other can't.Not that I'm aware of.
SamProtas commentedon Jul 1, 2017
@lpsmith Is there any reason not to include your
IntervalADT in this library with the appropriate ToField/FromField conversions? It sounds like that's a pretty safe addition from a correctness perspective and it would allow first-class two-way conversion of Intervals <-> Haskells.lpsmith commentedon Jul 1, 2017
I think it would be a worthy addition to postgresql-simple, and I would welcome a pull request of reasonable quality.
lpsmith commentedon Jul 1, 2017
In addition, I would probably accept a pull request that adds a
FromFieldinstance forNominalDiffTime, as well asFixed.Though I may have looked into supporting
Fixedonce, and was a bit scared off by some unfortunate ways postgres'snumerictype works. My memory is a bit fuzzy on that count.