SQL Server → PostgreSQL

TOP vs LIMIT: Migrating Row-Limited Queries

SQL Server TOP N and TOP N PERCENT become LIMIT and percentile subqueries in PostgreSQL.

TOP comes after SELECT in T-SQL. LIMIT goes at the end of SELECT in PostgreSQL. TOP PERCENT has no direct equivalent — use NTILE or a subquery with COUNT.

Simple TOP

SQL Server

SELECT TOP 10 * FROM logs ORDER BY created_at DESC;

PostgreSQL

SELECT * FROM logs ORDER BY created_at DESC LIMIT 10;

Analisador de Impacto

TOP without ORDER BY yields non-deterministic results — find every SELECT TOP in your project.

Abrir Análise de Projeto →