Conversation
| <> signed Builder.int32Dec (days x) | ||
| <> " days " | ||
| <> signed Builder.int64Dec (microseconds x) | ||
| <> " microseconds'" |
There was a problem hiding this comment.
This is not the most compact format. However it is very easy to interpret and does not require dealing with decimals. If desired, it could be made shorter by changing 1 months 2 days 3 microseconds to 1mon 2d 3us, which I think is the shortest way to render this format.
There was a problem hiding this comment.
These comments should be in the code.
| <> signed Builder.int64Dec (microseconds x) | ||
| <> " microseconds'" | ||
|
|
||
| parse :: A.Parser Interval |
There was a problem hiding this comment.
This is not a general purpose parser for Postgres intervals. It only does enough to parse intervals that Postgres emits.
It is too restrictive. For example, none of the parsers handle weeks because Postgres never renders intervals using weeks.
It is also too permissive. For example, it allows components to be repeated when that should sometimes be an error.
| {-# LANGUAGE LexicalNegation #-} | ||
| {-# LANGUAGE NumDecimals #-} | ||
|
|
||
| module Database.PostgreSQL.Simple.Interval where |
There was a problem hiding this comment.
This module exposes lots of utility functions that probably shouldn't be part of the public API. If desired, I could move this into an internal module and only re-export the interesting stuff from here.
There was a problem hiding this comment.
Having an explicit export list would be a good start even before I look any further.
| import qualified Database.PostgreSQL.Simple.Interval as I | ||
| import Test.Tasty | ||
|
|
||
| testTree :: TestEnv -> TestTree |
There was a problem hiding this comment.
I don't see any tests actully inserting and selecting any data from the postgresql server. These must be added.
|
To avoid any misunderstandings. As far as I understand this is true addition (new type) to the |
|
I released this as a separate package: https://hackage.haskell.org/package/postgresql-simple-interval-0.2025.7.9 |
Related issues and PRs:
This PR introduces a custom
Intervaltype because the duration types provided by thetimelibrary do not match theintervaltype in Postgres (months :: Int32, days :: Int32, microseconds :: Int64):DiffTime: not appropriateNominalDiffTime: only handles seconds (not days or months), allows picosecond precision (rather than micro), allows arbitrarily large durationsCalendarDiffTime: does not separate days from monthsCalendarDiffDays: does not handle secondsUnlike the existing
FromFieldinstance forCalendarDiffTime, this does not require a particularintervalstyleto be set in Postgres.