SQL Server TOP to PostgreSQL LIMIT Crosswalk

PostgreSQL's LIMIT covers SQL Server's basic TOP N case exactly, but TOP's PERCENT and WITH TIES variants need a genuinely different query shape, not a keyword swap.

Close equivalent Covers the common case, but has documented behavioral differences.

SQL Server feature
TOP
PostgreSQL equivalent
LIMIT

Main limitation: SQL Server's TOP clause appears right after SELECT (`SELECT TOP 10 * FROM ...`); PostgreSQL's LIMIT appears at the very end of the statement, after ORDER BY — the clause moves from the front of the query to the back, not just a renamed keyword in place.

Quick mapping

SQL Server TOP
PostgreSQL LIMIT

Examples

Selecting the top N rows by a sort order

SQL Server
SELECT TOP 10 * FROM products ORDER BY price DESC;
PostgreSQL
SELECT * FROM products ORDER BY price DESC LIMIT 10;
A direct, exact port for the common case — the clause just moves from the start of the query to the end.

The PERCENT variant has no direct LIMIT equivalent

SQL Server
SELECT TOP (10) PERCENT * FROM products ORDER BY price DESC;
PostgreSQL
SELECT * FROM products ORDER BY price DESC
LIMIT (SELECT CEIL(COUNT(*) * 0.10) FROM products);
PostgreSQL's LIMIT only accepts a row count, so a percentage-based cutoff must be computed with a scalar subquery first.

Caveats

Caveat

SQL Server's TOP clause appears right after SELECT (SELECT TOP 10 * FROM ...); PostgreSQL's LIMIT appears at the very end of the statement, after ORDER BY — the clause moves from the front of the query to the back, not just a renamed keyword in place.

Caveat

TOP without an explicit ORDER BY returns an arbitrary N rows determined by the query plan, exactly as unordered LIMIT does in PostgreSQL — neither is deterministic without an ORDER BY, and both should always be paired with one for predictable results.

Caveat

SQL Server's TOP (10) PERCENT (returning a percentage of matching rows) has no direct LIMIT equivalent; replicate it with LIMIT (SELECT CEIL(COUNT(*) * 0.10) FROM ...), a genuinely different query shape, not a simple keyword swap.

Caveat

SQL Server's TOP ... WITH TIES (including additional rows tied with the last value) has no LIMIT equivalent at all; PostgreSQL requires a window-function rewrite (e.g. RANK() OVER (ORDER BY ...) <= 10) to replicate tie-inclusive behavior.

References

  • Microsoft SQL Server docs — SELECT - TOP (Transact-SQL) — checked 2026-07-29
  • PostgreSQL docs — SELECT - LIMIT (v17) — checked 2026-07-29

Last verified 2026-07-29.