HexaBridge - SQL Server (T-SQL) Compatibility for PostgreSQL

HexaBridge brings SQL Server's T-SQL functions, data types, and operators to Community PostgreSQL - no proprietary fork required. 100% routine compatibility, delivered at native speed through C extensions.

0
SQL Server routine compatibility
0
SQL Server-Compatible Types
0
Functions & Aggregates
0
Operators

Deep T-SQL Compatibility on Community PostgreSQL

Moving from SQL Server to PostgreSQL usually means rewriting every T-SQL function call, every DATEADD/DATEDIFF, every CHARINDEX, and re-implementing types like nvarchar, uniqueidentifier, and hierarchyid by hand. HexaBridge removes that work: it resolves SQL Server functions and type names natively in PostgreSQL's sys schema, with SQL Server semantics (boundary-crossing DATEDIFF, trailing-space-insensitive nvarchar comparison, LEN trimming, T-SQL + string concatenation).

HexaBridge covers 100% of the SQL Server routine surface while preserving SQL Server semantics. Logic-heavy functions are written in C and direct maps are inlined by the planner, so the compatibility layer adds no performance overhead. It runs on Community PostgreSQL as-is with a single CREATE EXTENSION. No proprietary database fork required.

The compatibility no AI or migration tool can generate

AI and migration tools convert your schema and application code, but they cannot recreate the source database's built-in routines on PostgreSQL. HexaBridge provides exactly that runtime compatibility, so HexaRocket can achieve 100% automatic schema conversion. Without this layer, every built-in function your application relies on becomes a manual rewrite that no tool can fully automate.

Runs on Community PostgreSQL - no commercial fork needed

Works on Community PostgreSQL - No Proprietary Fork Required

HexaBridge for SQL Server is a standard PostgreSQL extension that installs with a simple CREATE EXTENSION hexabridge_mssql; command.

It is available to customers who migrate with HexaRocket and to customers of HexaCluster-approved partners. Contact us to see how it accelerates your SQL Server-to-PostgreSQL migration.

SQL Server-Compatible Types

12 types including nvarchar, nchar, datetime2, uniqueidentifier, rowversion, smallmoney, sql_variant, and a full hierarchyid. Optional geometry/geography via PostGIS.

SQL Server-Compatible Functions

180+ functions and aggregates - DATEADD, DATEDIFF, CHARINDEX, ISNULL, FORMAT, TRY_CONVERT, COMPRESS/DECOMPRESS, OPENJSON, and more.

Native Performance

Advanced performance through native C extensions. Logic-heavy functions run in C and direct maps are inlined by the planner, so the compatibility layer adds no performance overhead.

How It Works

-- Install HexaBridge for SQL Server on Community PostgreSQL
CREATE EXTENSION hexabridge_mssql;

-- Resolve sys.* / dbo.* names like SQL Server
SET search_path TO sys, public;

-- Use T-SQL functions naturally
SELECT charindex('cd', 'abcdef', 2); -- 3
SELECT dateadd('month', 2, '2021-01-31'); -- 2021-03-31 00:00:00
SELECT datediff('year', '2020-12-31', '2021-01-01'); -- 1  (boundary crossing)
SELECT isnull(NULL, 'default'); -- default

-- Optional: geometry/geography (requires PostGIS)
-- CREATE EXTENSION hexabridge_mssql_spatial CASCADE;

SQL Server-Compatible Data Types

HexaBridge provides 12 SQL Server data types that behave like their T-SQL counterparts - character-count length semantics, trailing-space-insensitive comparison, and SQL Server datetime precision. Optional geometry/geography are available via a separate PostGIS-backed submodule.

All types are created in the sys schema. With SET search_path TO sys, public;, they can be used by bare name - just like in SQL Server.

Optional spatial types geometry and geography map 1:1 onto PostGIS via the separate hexabridge_mssql_spatial submodule, which requires PostGIS. The core extension has no PostGIS dependency.

SQL Server-Compatible Functions

HexaBridge provides 180+ standalone T-SQL functions and aggregates that follow SQL Server semantics - boundary-crossing DATEDIFF, char-accurate CHARINDEX, LEN trailing-space trimming, ISNULL, .NET-style FORMAT, and more. Analytic window functions (ROW_NUMBER, RANK, DENSE_RANK, NTILE, LEAD, LAG, FIRST_VALUE, LAST_VALUE, CUME_DIST, PERCENT_RANK) are native PostgreSQL and work unchanged.

String / Character(15)

CHARINDEXcharindex(needle, haystack [, start])1-based, char-accurate (multibyte-safe) search with optional start; empty needle returns 0. C-implemented.
LENlen(str)Character length excluding trailing spaces (SQL Server semantics).
PATINDEXpatindex(pattern, str)1-based position of a LIKE pattern (%/_).
LEFT / RIGHTleft(str, n) / right(str, n)Leftmost / rightmost n characters.
REPLICATEreplicate(str, n)Repeats a string n times.
SPACEspace(n)Returns n spaces.
STUFFstuff(str, start, length, replace)Deletes length chars at start and inserts replace.
ISNUMERICisnumeric(str)1 if the string is a valid numeric literal, else 0.
CONCATconcat(v1, v2, ...)Concatenates, treating NULL as empty string.
CONCAT_WSconcat_ws(sep, v1, v2, ...)Concatenates with a separator, skipping NULLs.
STRING_SPLITstring_split(str, sep)Table-valued split into rows.
QUOTENAMEquotename(str [, quote_char])Delimits an identifier (default []).
STRstr(float [, length [, decimals]])Right-justified numeric-to-string; * overflow fill.
STRING_ESCAPEstring_escape(str, 'json')JSON-escapes a string.
UNICODEunicode(str)Unicode code point of the first character.

Date / Time(16)

DATEPARTdatepart(part, date)Extracts a date part (year, month, day, hour, ..., dayofyear, week, weekday). C-implemented token parsing.
DATEADDdateadd(part, n, date)Adds n of a date part with SQL Server end-of-month snapping.
DATEDIFFdatediff(part, start, end)Boundary-crossing count (not elapsed-unit subtraction). Overflow-checked.
DATEDIFF_BIGdatediff_big(part, start, end)Like DATEDIFF but returns bigint.
DATENAMEdatename(part, date)Textual name of a date part.
YEAR / MONTH / DAYyear(date) / month(date) / day(date)Component extractors.
EOMONTHeomonth(date [, months])Last day of the month (optionally offset).
GETDATE / GETUTCDATEgetdate() / getutcdate()Current statement timestamp (local / UTC). STABLE.
SYSDATETIME familysysdatetime() / sysutcdatetime() / sysdatetimeoffset()High-precision current timestamps.
DATEFROMPARTS familydatefromparts(y,m,d), datetimefromparts(...), smalldatetimefromparts(...), datetimeoffsetfromparts(...), timefromparts(...)Build datetime values from components.
DATETRUNCdatetrunc(part, date)Truncate to a date part.
DATE_BUCKETdate_bucket(part, n, date [, origin])Bucket a date into fixed-width bins.
ISDATEisdate(str)1 if the string parses as a date, else 0.
SWITCHOFFSET / TODATETIMEOFFSETswitchoffset(dto, tz) / todatetimeoffset(dt, tz)Adjust/attach a timezone offset. (tz-display semantics differ; functions present.)
FORMATformat(value, format [, culture]).NET-style date formatting.
DATETIME_ROUNDdatetime_round(ts)Exact SQL Server 1/300-second DATETIME tick rounding.

Numeric / Math(10)

ABS / SIGN / CEILING / FLOORabs(n) / sign(n) / ceiling(n) / floor(n)Type-preserving overloads (int/bigint/numeric/float).
ROUNDround(n, length [, function])Scale-preserving round; truncate flag (SQL Server semantics).
SQUAREsquare(n)n * n.
SQRT / EXP / POWERsqrt(n) / exp(n) / power(n, e)Standard math.
LOG / LOG10log(n [, base]) / log10(n)log(n) is natural log (T-SQL trap handled); log10 base-10.
PIpi()3.14159...
DEGREES / RADIANSdegrees(n) / radians(n)Angle conversion.
Trigonometrysin(n) / cos(n) / tan(n) / cot(n) / asin(n) / acos(n) / atan(n)Trigonometry (radians).
ATN2atn2(y, x)Two-argument arctangent.
RANDrand([seed])Pseudo-random float in [0,1).

Aggregate / Statistical(4)

STDEV / STDEVPstdev(expr) / stdevp(expr)Sample / population standard deviation.
VAR / VARPvar(expr) / varp(expr)Sample / population variance.
COUNT_BIGcount_big(expr)COUNT returning bigint.
CHECKSUM_AGGchecksum_agg(int)XOR-based group checksum (not value-identical to SQL Server).

Conversion(3)

TRY_CONVERT_*try_convert_int/bigint/numeric/float/date/datetime(text)Typed safe conversion; returns NULL on bad input.
CONVERT_DATETIME_STYLEconvert_datetime_style(value, style)SQL Server CONVERT date styles (1-126).
FORMAT (numeric)format(value, format [, culture]).NET-style numeric formatting (N/F/D/C/P/X and custom masks).

JSON(4)

ISJSONisjson(str)1 if valid JSON, else 0.
JSON_PATH_EXISTSjson_path_exists(json, path)1 if a JSON path resolves, else 0.
JSON_MODIFYjson_modify(json, path, value)Update/insert/delete at a JSON path.
OPENJSONopenjson(json)Table-valued expansion (key/value/type), objects and arrays.

Metadata / Catalog(12)

OBJECT_ID / OBJECT_NAMEobject_id(name) / object_name(id)Resolve object name <-> id.
OBJECT_SCHEMA_NAME / OBJECT_DEFINITIONobject_schema_name(id) / object_definition(id)Schema name / source text.
OBJECTPROPERTY / COLUMNPROPERTYobjectproperty(id, prop) / columnproperty(id, col, prop)Object/column property flags (IsTable, AllowsNull, ...).
COL_NAME / COL_LENGTHcol_name(id, n) / col_length(tab, col)Column name / length.
SCHEMA_ID / SCHEMA_NAMEschema_id([name]) / schema_name([id])Schema lookups.
TYPE_ID / TYPE_NAMEtype_id(name) / type_name(id)Type lookups.
DB_ID / DB_NAMEdb_id([name]) / db_name([id])Database lookups.
SERVERPROPERTY / DATABASEPROPERTYEXserverproperty(p) / databasepropertyex(db, p)Server / database properties.
APP_NAMEapp_name()Application name for the session.
INDEX_COL / INDEXPROPERTYindex_col(...) / indexproperty(...)Index metadata.
FILE / FILEGROUP metadatafile_id(name) / file_name(id) / filegroup_id(name) / filegroup_name(id)File / filegroup metadata.
STATS_DATEstats_date(id, stat_id)Statistics last-updated time.

Security(7)

SUSER_ID / SUSER_NAME / SUSER_SNAME / SUSER_SIDsuser_id([login]) / suser_name([id]) / suser_sname([sid]) / suser_sid([login])Login identity lookups.
USER_ID / USER_NAMEuser_id([name]) / user_name([id])Database-user lookups.
IS_MEMBER / IS_ROLEMEMBER / IS_SRVROLEMEMBERis_member(group) / is_rolemember(role) / is_srvrolemember(role)Role membership tests (mapped to PostgreSQL roles).
HAS_PERMS_BY_NAMEhas_perms_by_name(obj, class, perm)Permission check via has_table_privilege.
ORIGINAL_LOGINoriginal_login()Original session login.
LOGINPROPERTYloginproperty(login, prop)Login property lookup.
PERMISSIONSpermissions([object_id [, column]])Deprecated in SQL Server 2008+ but valid in older releases; returns the documented permission bitmap over PostgreSQL privileges.

System / Session(12)

ISNULLisnull(check, replacement)2-argument NULL substitution.
IIFiif(cond, t, f)Inline conditional.
CHOOSEchoose(index, v1, v2, ...)1-based pick; out-of-range returns NULL.
NEWID / NEWSEQUENTIALIDnewid() / newsequentialid()GUID generation.
SCOPE_IDENTITY / IDENT_CURRENTscope_identity() / ident_current(table)Last identity values.
CHECKSUM / BINARY_CHECKSUMchecksum(...) / binary_checksum(...)Deterministic 32-bit hash (not value-identical to SQL Server).
HOST_NAME / HOST_IDhost_name() / host_id()Client host info.
CONTEXT_INFO / SET_CONTEXT_INFOcontext_info() / set_context_info(bytea)Session context bytes.
SESSION_CONTEXT / SP_SET_SESSION_CONTEXTsession_context(key) / sp_set_session_context(key, value)Key/value session context.
FORMATMESSAGEformatmessage(msg, args...)printf-style message formatting.
PARSENAMEparsename('a.b.c.d', n)Extracts the nth name part from the right.
COMPRESS / DECOMPRESScompress(bytea|text) / decompress(bytea)GZIP compression, byte-interoperable with SQL Server.

Get HexaBridge for Your Migration

HexaBridge is available to customers who migrate their databases using HexaRocket, and to customers of HexaCluster-approved partners. We may open-source HexaBridge in the future - but you don't have to wait. Contact us today and we'll help you get started.

No proprietary PostgreSQL fork required. HexaBridge works as-is on Community PostgreSQL.

Learn About HexaRocket

Interested in HexaBridge? Available to HexaRocket migration customers and approved partners.