[PATCH] Add mssql_compat extension with DATEDIFF function

From: Myles Lewis <myles93(at)sbcglobal(dot)net>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: [PATCH] Add mssql_compat extension with DATEDIFF function
Date: 2025-11-25 03:25:09
Message-ID: B7AA1D86-75F6-4FB1-BB82-EFABA92AED9C@sbcglobal.net
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Attachment Content-Type Size
0001-feat-mssql_compat-Add-DATEDIFF-extension-for-SQL-Ser.patch application/octet-stream 83.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2025-11-25 03:33:18 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Chao Li 2025-11-25 03:03:50 Fixes bug in strlower_libc_sb()