Convert a SQL Server schema to PostgreSQL
Paste the CREATE TABLE statements from SQL Server and ERD Designer draws them as a model. Change the model's target database to PostgreSQL and every column's datatype is converted. You review each change before it is applied, then generate the PostgreSQL script.
What changes in the sample
Converted to PostgreSQL 17, these columns of the sample above change type. Everything else keeps its type; names, keys, nullability and lists of allowed values are left as they are.
| Column | SQL Server | PostgreSQL | Note |
|---|---|---|---|
Customers.CustomerId | INT identity | SERIAL | |
Customers.Email | NVARCHAR(255) | VARCHAR(255) | |
Customers.FullName | NVARCHAR(120) | VARCHAR(120) | |
Customers.Notes | NVARCHAR(MAX) | TEXT | |
Customers.IsActive | BIT | BOOLEAN | default: 1 → TRUE |
Customers.CreatedAt | DATETIME2(7) | TIMESTAMP(6) | default: SYSUTCDATETIME() → CURRENT_TIMESTAMP |
Orders.OrderId | BIGINT identity | BIGSERIAL | |
Orders.CustomerId | INT | INTEGER | |
Orders.PublicId | UNIQUEIDENTIFIER | UUID | default: NEWID() → gen_random_uuid() |
Orders.Total | DECIMAL(12,2) | NUMERIC(12,2) | |
Orders.PlacedAt | DATETIMEOFFSET(3) | TIMESTAMPTZ(3) | |
Orders.ReceiptPdf | VARBINARY(MAX) | BYTEA |
What it tells you
Where a conversion loses something, ERD Designer says so rather than picking for you. These are the messages for the sample:
- Customers.CreatedAt: PostgreSQL keeps at most 6 fractional-second digits — "(7)" became (6).
- Customers.CreatedAt: default SYSUTCDATETIME() is the time in UTC; it became CURRENT_TIMESTAMP, which is the session's local time — the same only where the database runs in UTC.
The PostgreSQL script
This is what ERD Designer generates for the sample, for PostgreSQL 17. Our test suite applies this conversion to a real PostgreSQL server and then reads the database back to confirm it matches the model exactly.
-- Create table Customers
CREATE TABLE "Customers" (
"CustomerId" SERIAL NOT NULL,
"Email" VARCHAR(255) NOT NULL,
"FullName" VARCHAR(120) NOT NULL,
"Notes" TEXT,
"IsActive" BOOLEAN NOT NULL DEFAULT TRUE,
"CreatedAt" TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "Customers_PK" PRIMARY KEY ("CustomerId")
);
-- Create table Orders
CREATE TABLE "Orders" (
"OrderId" BIGSERIAL NOT NULL,
"CustomerId" INTEGER NOT NULL,
"PublicId" UUID NOT NULL DEFAULT gen_random_uuid(),
"Total" NUMERIC(12,2) NOT NULL,
"PlacedAt" TIMESTAMP(3) WITH TIME ZONE NOT NULL,
"ReceiptPdf" BYTEA,
CONSTRAINT "Orders_PK" PRIMARY KEY ("OrderId")
);
-- Add unique constraint on Customers (Email)
ALTER TABLE "Customers" ADD CONSTRAINT "Customers_UQ1" UNIQUE ("Email");
-- Create index on Orders (PlacedAt)
CREATE INDEX "IX_Orders_PlacedAt" ON "Orders" ("PlacedAt");
-- Add foreign key Orders (CustomerId) → Customers (CustomerId)
ALTER TABLE "Orders" ADD CONSTRAINT "FK_Orders_Customers" FOREIGN KEY ("CustomerId") REFERENCES "Customers" ("CustomerId");
How to convert your own schema
- Paste your SQL Server script above and click the Open in ERD Designer button. The model opens laid out and ready to edit.
- Click the model's name in the toolbar to open the Edit Model form dialog, select PostgreSQL in the Target Database / Version list, and click the Apply Changes button.
- If PostgreSQL offers more than one way to store a kind of column, choose one and click the Continue button.
- Read the list of retyped columns and any warnings, then click the Apply Conversion button. Save the model to keep it.
- Press Generate DDL (the database icon) to copy or download the PostgreSQL script — or apply it to a database on your own network with the ERD Designer Agent.
What it reads, and what it does not
- It reads
CREATE TABLE,ALTER TABLE … ADD CONSTRAINTandCREATE INDEX: tables, columns, keys, foreign keys, unique constraints, check lists and indexes. Anything else in the script is skipped and listed. - It converts the schema, never the data: no rows are read, moved or changed.
- It does not convert views, stored procedures, functions, triggers or packages.
Which plan you need
Pasting a script and working with it as a model is free on the Basic plan, with no card. Converting a model to another database is part of the Pro and Advanced plans, which also generate its script and can apply it through the Agent.
Other conversions
- SQL Server to Oracle
- SQL Server to MySQL
- SQL Server to MariaDB
- SQL Server to SQLite
- SQL Server to Amazon Redshift
- SQL Server to Google BigQuery
- SQL Server to Snowflake
- Oracle to PostgreSQL
- MySQL to PostgreSQL
- MariaDB to PostgreSQL
- SQLite to PostgreSQL
- Amazon Redshift to PostgreSQL
- Google BigQuery to PostgreSQL
- Snowflake to PostgreSQL
Questions? Write to support@erddesigner.com. · ERD Designer™ · Terms · Privacy
ERD Designer™ is a trademark of ERD Designer, LLC.