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
I somehow managed to miss NodaTime's Interval type. This is a perfect match for PostgreSQL tstzrange, similarly to how we map DateInterval to PostgreSQL daterange.
I'm unsure if this is the appropriate place to report this, but it seems tstzrangearrays (tstzrange[]) are still mapped to NpgsqlRange<Instant>[] instead of Interval[] in 6.0.2. Is it done on purpose?
@madmox interesting... NodaTime Interval[] is mapped to PG tstzmultirange (and vice versa). However, I did not make special mappings to make PG tstzrange[] (non-multirange!) map back to NodaTime Interval[]. I guess my assumption was that now that multiranges are available, tstzrange[] would no longer be used much - though it's true some people are using pre-14 PostgreSQL where multirange isn't yet supported.
Do you have any particular reason for using tstzrange[] instead of tstzmultirange (aside from the PG version)? In any case, you can open this as a separate issue and I'll look into it.
PostgreSQL on Amazon RDS doesn't (yet) support PostgreSQL 14 engines (except in us-east-2, it seems), most recent option in our region is 13.3.
Actually, I didn't event know multiranges were a thing in PostgreSQL until today, when I upgraded to npgsql 6 and found out about the tstzrange[] issue. Although reading PostgreSQL documentation, if I understand it correctly, the "non-contiguous" constraint on multirange types might be an issue for us as we store a list of periods that might overlap.
I can easily get around the issue because I use Dapper on top of npgsql and already have type handlers so that Dapper correctly maps properties with non default types, so the fix is not top-priority. I even updated the handler so that it accepts both Interval[] and NpgsqlRange<Instant>[], in case the fix is integrated later and I forget about the issue when upgrading my nugets.
publicclassIntervalListHandler:SqlMapper.TypeHandler<List<Interval>>{publicoverrideList<Interval>Parse(objectvalue){// Looks like npgsql incorrectly maps tstzrange[] to NpgsqlRange<Instant>[]// although it correctly maps tstzrange to NodaTime.Interval.// See https://github.com/npgsql/npgsql/issues/4070 for details.if(valueisNpgsqlRange<Instant>[]){vartypedValue=(NpgsqlRange<Instant>[])value;returntypedValue?.Select(x =>newInterval(x.LowerBound,x.UpperBound)).ToList();}else{vartypedValue=(Interval[])value;returntypedValue?.ToList();}}publicoverridevoidSetValue(IDbDataParameterparameter,List<Interval>value){parameter.Value=value;((NpgsqlParameter)parameter).NpgsqlDbType=NpgsqlDbType.Array|NpgsqlDbType.Range|NpgsqlDbType.TimestampTz;}}
Activity
Document NodaTime interval mapping
Document NodaTime interval mapping (#144)
madmox commentedon Dec 22, 2021
I'm unsure if this is the appropriate place to report this, but it seems
tstzrangearrays (tstzrange[]) are still mapped toNpgsqlRange<Instant>[]instead ofInterval[]in 6.0.2. Is it done on purpose?roji commentedon Dec 22, 2021
@madmox interesting... NodaTime
Interval[]is mapped to PGtstzmultirange(and vice versa). However, I did not make special mappings to make PGtstzrange[](non-multirange!) map back to NodaTimeInterval[]. I guess my assumption was that now that multiranges are available,tstzrange[]would no longer be used much - though it's true some people are using pre-14 PostgreSQL where multirange isn't yet supported.Do you have any particular reason for using
tstzrange[]instead oftstzmultirange(aside from the PG version)? In any case, you can open this as a separate issue and I'll look into it.madmox commentedon Dec 22, 2021
PostgreSQL on Amazon RDS doesn't (yet) support PostgreSQL 14 engines (except in
us-east-2, it seems), most recent option in our region is 13.3.Actually, I didn't event know multiranges were a thing in PostgreSQL until today, when I upgraded to npgsql 6 and found out about the
tstzrange[]issue. Although reading PostgreSQL documentation, if I understand it correctly, the "non-contiguous" constraint on multirange types might be an issue for us as we store a list of periods that might overlap.roji commentedon Dec 22, 2021
@madmox the non-contiguous aspect of multiranges may indeed be a reason to continue using arrays, true.
If using NodaTime
Interval[]is important for you, please open a new issue - I can't promise I'll get around to it immediately though.madmox commentedon Dec 22, 2021
I can easily get around the issue because I use Dapper on top of npgsql and already have type handlers so that Dapper correctly maps properties with non default types, so the fix is not top-priority. I even updated the handler so that it accepts both
Interval[]andNpgsqlRange<Instant>[], in case the fix is integrated later and I forget about the issue when upgrading my nugets.But I opened the issue :)