I'd like to propose a new contrib extension: mssql_compat, which provides
SQL Server compatible date functions starting with DATEDIFF.
Problem: PostgreSQL lacks a native DATEDIFF() function, forcing users to
write verbose date arithmetic. Organizations migrating from SQL Server
encounter friction when porting date-based business logic.
Solution: datediff(datepart, start_date, end_date) returns precise,
contextually-aware date differences using a hybrid calculation model.
Key features:
- Supports day, week, month, quarter, year (with SQL Server aliases)
- Returns NUMERIC with 3 decimal precision
- Handles DATE, TIMESTAMP, TIMESTAMPTZ types
- IMMUTABLE STRICT PARALLEL SAFE
The patch:
- Compiles cleanly with no warnings
- Includes regression tests (all pass)
- Follows PostgreSQL coding conventions
- Based on current master
Attached: 0001-feat-mssql_compat-Add-DATEDIFF-extension-for-SQL-Ser.patch
Myles