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
SELECT TOP 10 * FROM products ORDER BY price DESC; SELECT * FROM products ORDER BY price DESC LIMIT 10; The PERCENT variant has no direct LIMIT equivalent
SELECT TOP (10) PERCENT * FROM products ORDER BY price DESC; SELECT * FROM products ORDER BY price DESC
LIMIT (SELECT CEIL(COUNT(*) * 0.10) FROM products); 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.