Convert SQL Server to PostgreSQL
A free online converter that translates SQL Server queries into PostgreSQL. Paste your SQL, press Translate, and Query Studio rewrites the syntax that differs between the two databases — instantly, with no login and nothing stored.
A well-worn path, usually driven by licensing. The query syntax converts cleanly; the behavioural differences — default collation, case sensitivity, and how each engine handles NULL in string operations — are what actually change results.
SQL Server → PostgreSQL example
Here is a real SQL Server query and the PostgreSQL output Query Studio produces:
SELECT TOP 10 u.id, u.name, COUNT(o.id) AS orders
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE u.created_at > '2024-01-01' AND u.active = 1
GROUP BY u.id, u.name
HAVING COUNT(o.id) > 3
ORDER BY orders DESC;SELECT
u.id,
u.name,
COUNT(o.id) AS orders
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.created_at > '2024-01-01'
AND u.active = 1
GROUP BY
u.id,
u.name
HAVING
COUNT(o.id) > 3
ORDER BY
orders DESC
LIMIT
10What changes from SQL Server to PostgreSQL
- Identifier quoting is rewritten from bracketed [identifiers] to double-quoted "identifiers".
- Row limiting is converted from SQL Server's TOP n to PostgreSQL's LIMIT n, including any OFFSET for pagination.
- Null-handling functions such as ISNULL() are mapped to COALESCE().
- Current-timestamp functions like GETDATE() become NOW() / CURRENT_TIMESTAMP.
- The result is re-indented and keyword-cased in PostgreSQL style so it's ready to paste and run.
SQL Server to PostgreSQL data type mapping
Query Studio translates queries, not schemas. When you come to move the tables themselves, this is what changes between SQL Server and PostgreSQL:
| SQL Server | PostgreSQL | Watch out for |
|---|---|---|
| INT IDENTITY(1,1) | INTEGER GENERATED ALWAYS AS IDENTITY | Direct equivalent. |
| NVARCHAR(n) / NVARCHAR(MAX) | VARCHAR(n) / TEXT | Postgres text is UTF-8 throughout, so the N prefix has no meaning and no cost. |
| DATETIME2 | TIMESTAMP | Direct equivalent. |
| DATETIMEOFFSET | TIMESTAMPTZ | Direct equivalent. |
| BIT | BOOLEAN | 1/0 becomes TRUE/FALSE — check anything comparing the column to a number. |
| UNIQUEIDENTIFIER | UUID | Direct equivalent. |
| VARBINARY(MAX) | BYTEA | Direct equivalent. |
| MONEY | NUMERIC(19,4) | Postgres has a MONEY type but it is locale-dependent and generally avoided. |
| [bracketed identifiers] | "double-quoted identifiers" | Postgres folds unquoted identifiers to lowercase; SQL Server preserves case. A quoted "MyTable" is not the same object as MyTable. |
SQL Server to PostgreSQL: what actually catches people out
Syntax is the part a translator can fix. These are the differences that survive a clean conversion and show up later as wrong results rather than as errors.
TOP and OFFSET/FETCH are not interchangeable
SQL Server's TOP n cannot be combined with OFFSET, so paginated T-SQL uses OFFSET … FETCH NEXT, which requires an ORDER BY. PostgreSQL's LIMIT/OFFSET has no such requirement — but a LIMIT without an ORDER BY returns an arbitrary subset in both, so any query that was relying on the mandatory ORDER BY should keep it.
SELECT TOP 10 * FROM users ORDER BY created_at DESC;SELECT * FROM users ORDER BY created_at DESC LIMIT 10;Bracketed identifiers hide a case-sensitivity change
[MyTable] in T-SQL is just quoting; SQL Server is case-insensitive by default collation. Translating it to "MyTable" in PostgreSQL makes it case-sensitive and permanently mixed-case. Unless you want to quote every reference forever, lowercase the identifiers instead of quoting them.
Default collation is case-insensitive in one and not the other
SQL Server's common default collation compares strings case-insensitively, so WHERE name = 'smith' matches 'Smith'. PostgreSQL is case-sensitive. Every equality comparison on text is a behaviour change — use LOWER() on both sides, or a citext column, or an expression index on LOWER(name).
GETDATE() is not the same instant as NOW()
GETDATE() returns server local time; PostgreSQL's NOW() returns a timestamptz in the session time zone. If the SQL Server was running in a non-UTC zone, converting the function without converting the stored data shifts every new row relative to the old ones.
MERGE exists in both and behaves differently
PostgreSQL gained MERGE in 15. Before that the idiom is INSERT … ON CONFLICT, which is not a general MERGE and cannot delete. Check the target version before assuming a T-SQL MERGE statement carries over.
What this converter will not do
Query Studio translates SQL syntax. Being honest about the boundary is more useful than claiming there isn’t one — and on SQL Server → PostgreSQL specifically, these are the three that matter most:
Stored procedures, functions and triggers
Procedural code — PL/pgSQL, T-SQL procedures, MySQL routines — is a different language in every engine, with different control flow, error handling, variable declaration and transaction semantics. Query Studio translates queries, not programs. These have to be ported by hand.
Anything that depends on data rather than syntax
Whether a value fits the target type, whether a date is real, whether a text column's contents are valid UTF-8 — none of that is visible in the query. A translation can be syntactically perfect and still fail on the first row of the import.
Vendor-specific extensions
PostGIS geometry, MySQL spatial functions, SQL Server's FOR XML and hierarchyid, BigQuery's nested/repeated model, Snowflake's time travel. Where there is no equivalent concept, there is no translation — only a redesign.
The full list of what a syntax translator cannot do is on the Query Studio page.
How to convert SQL Server to PostgreSQL
- Open the Query Studio editor and choose SQL Server as the “From” dialect.
- Choose PostgreSQL as the “To” dialect.
- Paste your SQL Server query and press Translate — copy the PostgreSQL result.
Try it with your own query
The editor is preloaded with SQL Server → PostgreSQL. You can also explain, format, validate and analyze the result.
Convert SQL Server to PostgreSQL now →Working with the data rather than the schema? Open a large CSV, JSON or Parquet file and query it with SQL — no upload, no row limit, and files far past what Excel will open.
SQL Server to PostgreSQL FAQ
Is this SQL Server to PostgreSQL converter free?
Yes — it's completely free with no account, no sign-up and no usage limits. Your query is processed to return the result and never stored.
Is the SQL Server to PostgreSQL conversion accurate?
Query Studio rewrites syntax deterministically using real SQL parsers, so it gives the same result every time — there is no AI involved and no variation between runs. It handles the differences listed above automatically. What it cannot do is anything semantic: stored procedures, triggers, vendor extensions and performance characteristics all need a human. Review complex, vendor-specific queries before running them in production.
What breaks when migrating from SQL Server to PostgreSQL?
The differences that most often cause problems on this pair: TOP and OFFSET/FETCH are not interchangeable; Bracketed identifiers hide a case-sensitivity change; Default collation is case-insensitive in one and not the other; GETDATE() is not the same instant as NOW(); MERGE exists in both and behaves differently. Each is explained in full above, with before-and-after examples where seeing it is quicker than reading about it.
How do SQL Server data types map to PostgreSQL?
The full mapping table is above and covers 9 types. The ones that are not a straight rename: NVARCHAR(n) / NVARCHAR(MAX) → VARCHAR(n) / TEXT, BIT → BOOLEAN, MONEY → NUMERIC(19,4), [bracketed identifiers] → "double-quoted identifiers". Note that Query Studio translates queries rather than schemas — the table is there to tell you what your CREATE TABLE statements need, not to rewrite them for you.
Does this SQL Server to PostgreSQL converter use AI?
No. Every result is computed by real SQL parsers and rule engines, which is what makes it free, instant, unlimited and identical on every run. Nothing is sent to a model, so there are no rate limits, no per-request cost to pass on, and no possibility of a confidently wrong answer that looks plausible.
Can I convert PostgreSQL back to SQL Server?
Yes. Use the PostgreSQL to SQL Server converter, or press the Swap (⇄) button inside the editor to flip the direction instantly. Note that a round trip is not guaranteed to return your original text — both directions normalise formatting, and where one dialect has no equivalent for a feature the information is genuinely lost rather than recoverable.