[PATCH] Add mssql_compat extension with DATEDIFF function - Mailing list pgsql-hackers

From Myles Lewis
Subject [PATCH] Add mssql_compat extension with DATEDIFF function
Date
Msg-id B7AA1D86-75F6-4FB1-BB82-EFABA92AED9C@sbcglobal.net
Whole thread Raw
List 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

pgsql-hackers by date:

Previous
From: Chao Li
Date:
Subject: Fixes bug in strlower_libc_sb()
Next
From: Peter Smith
Date:
Subject: Re: Proposal: Conflict log history table for Logical Replication