SQL Server to PostgreSQL: Comparing and Migrating Database Schemas

A SQL Server to PostgreSQL migration — often to cut licensing costs — starts with the schema. The two engines are closer than MySQL and PostgreSQL in some ways, but their type systems, identity handling, and object qualification still diverge enough to trip up a manual migration.

SQL server to PostgreSQL migration: side-by-side DDL diff in FoxSchema

Identity columns in a SQL Server to PostgreSQL migration

SQL Server's IDENTITY(1,1) maps to PostgreSQL's GENERATED … AS IDENTITY or a SERIAL-backed sequence. A schema diff recognises identity columns and emits the PostgreSQL form rather than copying the T-SQL syntax.

Type differences

  • NVARCHAR/NCHAR → varchar/text (PostgreSQL text is Unicode by default).
  • DATETIME2 → timestamp; BIT → boolean.
  • UNIQUEIDENTIFIER → uuid.
  • MONEY → numeric.

Schema qualification

SQL Server objects are qualified as schema.object (commonly dbo). PostgreSQL uses schemas too, but the default is public. Foreign keys and views referencing dbo.Table must be requalified to the target schema — a good diff tool does this automatically.

What needs manual review

Stored procedures, functions, and triggers are written in T-SQL and will not run on PostgreSQL's PL/pgSQL without a rewrite. Views can often be adapted but should be reviewed. A cross-dialect tool flags these up front so they do not surprise you mid-migration.

SQL Server to PostgreSQL migration: details that bite later

NVARCHAR and VARCHAR both map to text types in PostgreSQL, which stores Unicode natively, so collation and length limits deserve a second look. UNIQUEIDENTIFIER maps to uuid, DATETIME2 to timestamp, and BIT to boolean. Square-bracket quoting becomes double quotes, and T-SQL features such as computed columns, filtered indexes and TOP queries need manual review or a rewrite. Default schemas differ too: dbo is the convention in SQL Server, while PostgreSQL relies on public and a search path, so check where unqualified names will resolve.

SQL Server to PostgreSQL migration: compare, then migrate

Point a schema diff at your SQL Server database and the PostgreSQL target to generate the structural DDL, then handle procedural objects as a checklist. FoxSchema supports both dialects (plus Azure SQL). Get started.

Further reading: for more on SQL server to PostgreSQL migration, see the SQL Server documentation and the PostgreSQL documentation.

Scroll to Top