← Every conversion

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.

You sign up free and land on your model. Your script is held for 15 minutes and deleted from our server the moment you open it.

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.

ColumnSQL ServerPostgreSQLNote
Customers.CustomerIdINT identitySERIAL
Customers.EmailNVARCHAR(255)VARCHAR(255)
Customers.FullNameNVARCHAR(120)VARCHAR(120)
Customers.NotesNVARCHAR(MAX)TEXT
Customers.IsActiveBITBOOLEANdefault: 1 → TRUE
Customers.CreatedAtDATETIME2(7)TIMESTAMP(6)default: SYSUTCDATETIME() → CURRENT_TIMESTAMP
Orders.OrderIdBIGINT identityBIGSERIAL
Orders.CustomerIdINTINTEGER
Orders.PublicIdUNIQUEIDENTIFIERUUIDdefault: NEWID() → gen_random_uuid()
Orders.TotalDECIMAL(12,2)NUMERIC(12,2)
Orders.PlacedAtDATETIMEOFFSET(3)TIMESTAMPTZ(3)
Orders.ReceiptPdfVARBINARY(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:

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

  1. Paste your SQL Server script above and click the Open in ERD Designer button. The model opens laid out and ready to edit.
  2. 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.
  3. If PostgreSQL offers more than one way to store a kind of column, choose one and click the Continue button.
  4. Read the list of retyped columns and any warnings, then click the Apply Conversion button. Save the model to keep it.
  5. 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

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

Questions? Write to support@erddesigner.com. · ERD Designer™ · Terms · Privacy

ERD Designer™ is a trademark of ERD Designer, LLC.