Reasonable support for java.time.Duration
-> Interval conversion
#1281
Labels
Milestone
java.time.Duration
-> Interval conversion
#1281
Describe the feature
Working with the standard
java.time.Duration
class in postgres is unnecessarily painful.Use cases
I ran into this issue with a simple query that invokes a stored procedure:
where the code supplying the
interval
is handed ajava.time.Duration
. Having done some testing inpsql
, Postgres supports ISO-8601 duration strings perfectly well in a query - i.e.P1Y::interval
gets you an interval of a year. Great! So, I try to passTuple.of(duration.toString(), ...)
.vertx-pg-client helpfully (and silently!) replaces the duration with
NULL
. Very surprising when my queries start returning tens of thousands of result.Tried a few incantations of
::varchar
and similar trying to head-fake vertx-pg-client into doing the right thing. No luck.Solutions:
Tuple
should really just accept ajava.time.Duration
and convert it to anInterval
(or whatever) under the hoodDuration
toInterval
in a constructor, so if none of the above is acceptable, there is at least a low-complexity way of doing that (could be as simple as creating an interval with the number of seconds and microseconds in the duration - though it would be more polite to anyone reading queries from the database log to extract those elements that don't have varying lengths - i.e. days, hours, minutes, seconds, microseconds)Contribution
I might consider it.
Quick'n'dirty, unpretty code to do the job with some necessary inaccuracy around years and months (but good enough for my current purposes):
The text was updated successfully, but these errors were encountered: