Using Npgsql 9.0.3/NodaTime 3.2.2
Time ranges with inclusive bounds ('[', ']', '[]') and use of infinity causes an out of range error in NodaTime when converting ("Operation would overflow range of Instant")
Minimal reproduction case
static void Main(string[] args)
{
string connStr = "Host=localhost;Username=postgres;Password=postgres;Database=postgres";
NpgsqlDataSourceBuilder dsb = new(connStr);
dsb.UseNodaTime();
NpgsqlDataSource npgsqlDataSource = dsb.Build();
using NpgsqlConnection conn = npgsqlDataSource.CreateConnection();
conn.Open();
string sql = "select tstzrange('2024-12-10 10:22:18.719432-06', 'infinity','[)') as val"; // Non-Inclusive Of Infinity
using NpgsqlCommand cmd = new(sql, conn);
object interval = cmd.ExecuteScalar(); // Works Fine
Console.WriteLine(interval);
sql = "select tstzrange('2024-12-10 10:22:18.719432-06', 'infinity','[]') as val"; // Note Range Inclusive [] used
cmd.CommandText = sql;
interval = cmd.ExecuteScalar(); // Errors With NodaTime exception Operation would overflow range of Instant
Console.WriteLine(interval);
}
The tstzranges are valid in PostgreSQL, though the difference between inclusive and exclusive of infinity is probably academic.
Probably better behavior would be to treat as exclusive of infinity values (i.e. ignore the inclusive in the specific case of +/-infinity) and permit the creation of the NodaTime.Interval object?