Microsoft SQL Server Wrapper
Overview
Microsoft SQL Server Wrapper
Microsoft SQL Server is a proprietary relational database management system developed by Microsoft. It's used by enterprises worldwide for transactional workloads, analytics, and mission-critical applications, with SQL Server 2025 adding built-in AI capabilities, vector search, and native JSON support.
The SQL Server Wrapper brings your SQL Server tables and views into Postgres as queryable foreign tables. Query data with plain SQL, use subqueries in table definitions, and take advantage of pushdown for where, order by, limit, and aggregate clauses — so queries run on SQL Server, not locally. Read-only, and works with Supabase Vault for secure connection string management.
Supported Data Types
| Postgres Type | SQL Server Type |
|---|---|
| boolean | bit |
| char | tinyint |
| smallint | smallint |
| real | float(24) |
| integer | int |
| double precision | float(53) |
| bigint | bigint |
| numeric | numeric / decimal |
| text | varchar / char / text |
| date | date |
| timestamp | datetime / datetime2 / smalldatetime |
| timestamptz | datetime / datetime2 / smalldatetime |
Preparation
Before you get started, make sure the wrappers extension is installed on your database:
_10create extension if not exists wrappers with schema extensions;
and then create the foreign data wrapper:
_10create foreign data wrapper mssql_wrapper_10 handler mssql_fdw_handler_10 validator mssql_fdw_validator;
Secure your credentials (optional)
By default, Postgres stores FDW credentials inside pg_catalog.pg_foreign_server in plain text. Anyone with access to this table will be able to view these credentials. Wrappers is designed to work with Vault, which provides an additional level of security for storing credentials. We recommend using Vault to store your credentials.
The connection string uses ADO.NET format with semicolon-delimited parameters. Note: use encrypt=DANGER_PLAINTEXT only in development — always use encrypt=true in production.
_10select vault.create_secret(_10 'Server=localhost,1433;User=sa;Password=my_password;Database=master;IntegratedSecurity=false;TrustServerCertificate=true;encrypt=DANGER_PLAINTEXT;ApplicationName=wrappers',_10 'mssql',_10 'MS SQL Server connection string for Wrappers'_10);
Supported connection string parameters:
| Parameter | Description |
|---|---|
Server | Host and port of the SQL Server instance, e.g. host,1433 |
User | SQL Server login account |
Password | Password for the SQL Server account |
Database | Name of the database |
IntegratedSecurity | Set to false; Windows/Kerberos auth is not supported |
TrustServerCertificate | true or false — whether to trust the server's TLS certificate |
Encrypt | true, false, or DANGER_PLAINTEXT — controls TLS encryption |
ApplicationName | Optional label for the connection |
Connecting to SQL Server
We need to provide Postgres with the credentials to connect to SQL Server. We can do this using the create server command:
With Vault:
_10create server mssql_server_10 foreign data wrapper mssql_wrapper_10 options (_10 conn_string_id '<key_ID>' -- The Key ID from above._10 );
Without Vault:
_10create server mssql_server_10 foreign data wrapper mssql_wrapper_10 options (_10 conn_string 'Server=localhost,1433;User=sa;Password=my_password;Database=master;IntegratedSecurity=false;TrustServerCertificate=true;encrypt=DANGER_PLAINTEXT;ApplicationName=wrappers'_10 );
Resources
Details
Third-party integrations and docs are managed by Supabase partners.