Range function resolution fails for column (tstzrange) and parameter (tsrange)
See original GitHub issueWith 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:
- Created 5 years ago
- Comments:31 (22 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Bah, date/time insanity… That’s why it should all be delegated to a library which actually knows about all that complexity…
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.