PostgreSQL basics: LIMIT, OFFSET, ILIKE and :: casts
PostgreSQL follows the SQL standard closely and adds a few handy shortcuts.
Dialects · PostgreSQL
Free. No sign up. Your progress stays in this browser.
What you will learn
PostgreSQL is popular with startups and analytics teams, and Amazon Redshift is based on it.
Its LIKE is case sensitive, which surprises many newcomers.
The basics
PostgreSQL follows the SQL standard closely. Amazon Redshift is based on it, so this track fits Redshift too.
SELECT customer, amount
FROM invoices
ORDER BY amount DESC
LIMIT 5 OFFSET 5LIMIT takes the first rows, OFFSET skips rows first: page 2 of 5 rows is LIMIT 5 OFFSET 5.
SELECT customer FROM invoices WHERE customer ILIKE '%labs%'In PostgreSQL LIKE is case sensitive. ILIKE ignores case. value::type is a short form of CAST(value AS type), for example '2026-03-01'::date. Use COALESCE for empty values; PostgreSQL has no NVL or ISNULL function.
Worked examples
Example 1
Page 2 of the deal list, 10 per page.
SELECT account, amount
FROM deals
ORDER BY amount DESC
LIMIT 10 OFFSET 10OFFSET skips the first page.
Example 2
Accounts containing “labs”, any case.
SELECT account FROM deals WHERE account ILIKE '%labs%'ILIKE ignores capital letters.
Reading helps, typing makes it stick. Every task gives you a fresh table, and your query is checked by a real database.
Try a taskCommon mistakes
- Using LIKE and missing rows because of capital letters.
- Using NVL or ISNULL, which PostgreSQL does not have.
- Paging without ORDER BY.
Where you will use it at work
- Product analytics on app databases.
- Startups and SaaS reporting.
- Amazon Redshift warehouses.
Questions people ask
What does :: do?
It casts a value: '2026-03-01'::date is CAST('2026-03-01' AS date).
Does PostgreSQL support FETCH FIRST?
Yes, as well as LIMIT.
How do I fill empty values?
With COALESCE.
Ready to write it yourself?
Practice LIMIT, OFFSET and ILIKEFurther reading
Related guides
SQL Practice is independent and not affiliated with the maker of this database. The exercises run on SQLite in your browser and imitate this dialect’s syntax for practice.