Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map DbType.DateTime to timestamptz #4106

Closed
roji opened this issue Nov 8, 2021 · 0 comments · Fixed by #4104
Closed

Map DbType.DateTime to timestamptz #4106

roji opened this issue Nov 8, 2021 · 0 comments · Fixed by #4104

Comments

@roji
Copy link
Member

roji commented Nov 8, 2021

There are 3 date/time-related values in the System.Data DbType enum:

  • DbType.DateTime. Currently mapped to timestamp without time zone. Discouraged for use for columns on SQL Server.
  • DbType.DateTime2. Currently mapped to timestamp without time zone as well. Encouraged for use for columns on SQL Server.
  • DbType.DateTimeOffset. Currently mapped to timestamp with time zone. There is no actual type that corresponds to DateTimeOffset in PostgreSQL.

As part of our timestamp redo for 6.0, we'll change DbType.DateTime to map to timestamp with time zone. Reasoning:

  • We believe the default PG type wanted in most scenarios is timestamptz (UTC timestamp), DbType.DateTime expresses that.
  • Both linq2db and Dapper set DbType.DateTime by default when they send a DateTime, this enforces DbType.DateTime as the "default" option (but see this issue where Dapper stopped setting DbType altogether for DateTime, to allow Npgsql to infer from the Kind).
  • Users are likely to choose either DbType.DateTime or DateTime2 for sending a timestamp. Having both map to timestamp without time zone seems like a pit of failure; this would throw if a UTC DateTime is provided, but if a DbType.DateTime parameter is inserted into a timestamptz column, a silent time zone conversion would be done on the PG side instead.
  • We considered mapping the other way around (DateTime2 -> timestamptz, DateTime -> timestamp), since in SQL Server DateTime2 is the default. However, it seems that while DateTime2 is the default column type, DateTime is routinely used when sending parameters (see especially linq2db and Dapper).
@roji roji added this to the 6.0.0 milestone Nov 8, 2021
roji added a commit to roji/Npgsql.Doc that referenced this issue Nov 8, 2021
vonzshik added a commit that referenced this issue Nov 8, 2021
Closes #4106
Closes #4105

Co-authored-by: Shay Rojansky <roji@roji.org>
roji added a commit to npgsql/doc that referenced this issue Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants