Back
Microsoft SQL Server Wrapper

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 TypeSQL Server Type
booleanbit
chartinyint
smallintsmallint
realfloat(24)
integerint
double precisionfloat(53)
bigintbigint
numericnumeric / decimal
textvarchar / char / text
datedate
timestampdatetime / datetime2 / smalldatetime
timestamptzdatetime / datetime2 / smalldatetime

Preparation

Before you get started, make sure the wrappers extension is installed on your database:


_10
create extension if not exists wrappers with schema extensions;

and then create the foreign data wrapper:


_10
create 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.


_10
select 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:

ParameterDescription
ServerHost and port of the SQL Server instance, e.g. host,1433
UserSQL Server login account
PasswordPassword for the SQL Server account
DatabaseName of the database
IntegratedSecuritySet to false; Windows/Kerberos auth is not supported
TrustServerCertificatetrue or false — whether to trust the server's TLS certificate
Encrypttrue, false, or DANGER_PLAINTEXT — controls TLS encryption
ApplicationNameOptional 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:


_10
create 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:


_10
create 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

DeveloperSupabase
DocumentationLearn

Third-party integrations and docs are managed by Supabase partners.

Get started with Microsoft SQL Server Wrapper and Supabase.