question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Range function resolution fails for column (tstzrange) and parameter (tsrange)

See original GitHub issue

With the following database table:

create table public.some_record (
  during tstzrange
);

The following model:

public class SomeRecord
{
    public NpgsqlRange<DateTime> During { get; set; }
}

causes the following exception on insert:

2018-08-02 15:36:52.732 +02:00 [Error] [8504472] [14] [] [] [:] [Microsoft.EntityFrameworkCore.Database.Command] Failed executing DbCommand ("17"ms) 
[Parameters=["@p0='[2018-08-02 15:36:51,)' (DbType = Object)"], CommandType='Text', CommandTimeout='600']"
""INSERT INTO public.some_record (during)
VALUES (@p0);"
Npgsql.PostgresException (0x80004005): 42804: column "during" is of type tstzrange but expression is of type tsrange
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 1032
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming) in C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs:line 444
   at Npgsql.NpgsqlDataReader.NextResult() in C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs:line 332
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1219
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) in C:\projects\npgsql\src\Npgsql\NpgsqlCommand.cs:line 1130

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:31 (22 by maintainers)

github_iconTop GitHub Comments

3reactions
rojicommented, Aug 6, 2018

To supplement what @Brar said above, NodaTime also uses the IANA timezone database, which is pretty much the standard outside of the Windows world. The advantage of NodaTime is a sane date/time type hierarchy along with the timezone database - basically everything is taken care of for you.

Not to distract from the wider discussion, but while every time zone has a definition of DST, not every locale in the time zone necessarily observes it:

Bah, date/time insanity… That’s why it should all be delegated to a library which actually knows about all that complexity…

2reactions
dpsennercommented, Aug 4, 2018

Incidentally I came to the same conclusions. If team lead agrees we are going to set sails with nodatime instants, tsrange and timestamp without timezones. Where required we will introduce additional columns for client local times and/or the timezone id of the client that created or updated that specific entity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set the resolution of the TSTZRANGE Postgres type?
Here is the query to create a timestamp range with a millisecond resolution: CREATE TYPE tstzrange3 AS RANGE ( subtype = timestamp (3)...
Read more >
Documentation: 15: 8.17. Range Types
In this case the data type is tsrange (short for “timestamp range”), and timestamp is the subtype. The subtype must have a total...
Read more >
Range data types [YSQL]
Specify "tsrange" values using the constructor function. The constructor function for a particular range data type has the same name as the range...
Read more >
2 B-tree indices OR 1 GiST index on tsrange
I have regular B-Tree indices on the starts_at and ends_at columns, therefore the first query is always using them. However, unless I define...
Read more >
PostgreSQL - Data Type
In this chapter, we will discuss about the data types used in PostgreSQL. While creating table, for each column, you specify a data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found