reconsider approach to Span
integration for PostgreSQL in jiff-diesel
(and probably jiff-sqlx
)
#251
Labels
enhancement
New feature or request
Right now, the
Span
wrapper type injiff-diesel
andjiff-sqlx
only supports decoding from a PostgreSQL interval. All suchSpan
values have, at most, non-zero months, days and/or microseconds. All other units are always zero.Encoding is not provided currently because it has two problems with it:
(months, days, microseconds)
and a JiffSpan
has many more units than that, one has to convert aSpan
into a PostgreSQL interval using only months, days and microseconds. I believe this is possible to do in a way that always preserves the exact physical duration (so long as we can assume that there are always 7 days in a week, which Jiff does indeed do). That is, this conversion step never needs to make assumptions like "there are always 30 days in a month" or "there are always 24 hours in a day." This can be done, it just requires a bit of work.Span
when we use a PostgreSQL interval. For example, it would erase the difference between2 hours
and120 minutes
.So while (1) is solvable, (2) really isn't. (2) is a concern to me because it could be potentially surprising to drop semantic information like that silently. So there is an open question for how to deal with it. Here are some choices:
Span
wrappers. One that integrates with PostgreSQL intervals and potentially loses information, and another wrapper that uses a plainTEXT
field with the friendly duration format to non-lossily encode and decode aSpan
. The downside is that you don't get native PostgreSQL interval support.I'm partial to (3). It makes the wrappers a bit more complicated, but not significantly so IMO. We could name them,
SpanInterval
andSpanNonLossy
or something.Ref #241 (comment)
The text was updated successfully, but these errors were encountered: