If you frequently write SQL queries, you should be familiar with the LIMIT keyword. It limits your results to a certain number of rows. LIMIT is not considered part of the SQL standard.

PostgreSQL has another way to achieve the same results while conforming to SQL standard: FETCH. FETCH skips a number of rows and then fetches a precise number of rows.

Examples

SELECT user_id, first_name, last_name
FROM users
FETCH FIRST 1 ROW ONLY;
SELECT user_id, first_name, last_name
FROM users
WHERE is_active = TRUE
FETCH FIRST 5 ROW ONLY;