fix: MsSQL timezone-safe timestamp normalization via AT TIME ZONE#51
fix: MsSQL timezone-safe timestamp normalization via AT TIME ZONE#51
Conversation
Wrap MsSQL normalize_timestamp() with explicit UTC conversion using CAST(value AS DATETIMEOFFSET) AT TIME ZONE 'UTC'. MsSQL cannot set a session timezone, so we normalize explicitly in the SQL to ensure consistent cross-database timestamp comparisons. Closes #30 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d62aedf23
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
data_diff/databases/mssql.py
Outdated
| # Convert to UTC to ensure consistent cross-database comparisons. | ||
| # MsSQL cannot set a session timezone, so we normalize explicitly. | ||
| # Cast to datetimeoffset (assumes server local time), then convert to UTC. | ||
| utc_value = f"CAST({value} AS DATETIMEOFFSET) AT TIME ZONE 'UTC'" |
There was a problem hiding this comment.
Preserve compatibility with pre-2016 SQL Server
normalize_timestamp() now hard-codes AT TIME ZONE 'UTC', but AT TIME ZONE is only supported on SQL Server 2016+ (per Microsoft T-SQL docs). On SQL Server 2012/2014 this expression is a syntax error, so any diff that touches temporal columns will fail at query time, whereas the previous implementation used only FORMAT/SUBSTRING and remained compatible.
Useful? React with 👍 / 👎.
CAST(datetime AS DATETIMEOFFSET) assigns +00:00 unconditionally, not the server's local timezone. UTC conversion only helps for datetimeoffset columns (TimestampTZ). For timezone-naive datetime/datetime2 columns, the conversion is a no-op — values are used as-is since the source timezone is unknown. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
normalize_timestamp()with explicit UTC conversionCAST(value AS DATETIMEOFFSET) AT TIME ZONE 'UTC'before formattingKey Files
data_diff/databases/mssql.py—normalize_timestamp()now converts to UTCTest plan
Closes #30
🤖 Generated with Claude Code