Learn PostgreSQL: practise standard SQL and the Postgres differences
PostgreSQL sticks closely to the SQL standard, and much of it reads exactly like our practice database. This page explains what PostgreSQL is, where it behaves differently, the psql commands you need on day one and how to install it. You practise straight away in your browser.
In short: PostgreSQL (Postgres for short) is a free database system you may use for any purpose, commercial included. You join text with || and limit rows with LIMIT, just as you do here. What changes: LIKE is case-sensitive (use ILIKE to ignore case), unquoted names are folded to lower case, dates are formatted with to_char(), and automatic IDs come from GENERATED … AS IDENTITY.
What is PostgreSQL?
PostgreSQL is an object-relational database management system. It grew out of the POSTGRES project at the University of California, Berkeley, and today it is the open source descendant of that code. The documentation stresses two points: PostgreSQL supports a large part of the SQL standard, and its liberal licence lets anyone use, modify and distribute it free of charge, whether for private, commercial or academic work. “Postgres” is still considered an official name of the project.
Its feature list includes foreign keys, triggers, updatable views, transactions and the option to extend the system with your own data types, functions and procedural languages. For a learner, the practical upshot is simple: if you write clean standard SQL, you will feel at home in PostgreSQL quickly.
Why this course works for PostgreSQL
Our exercises run on SQLite, and SQLite writes many things the PostgreSQL way: joining text with ||, LIMIT and OFFSET, COALESCE, CASE, CTEs with WITH and window functions. SELECT, WHERE, JOIN, GROUP BY and HAVING are the same everywhere anyway. The places where PostgreSQL is stricter or different are listed below with examples. For an overview of all four systems, see MySQL vs PostgreSQL vs SQL Server. When you show the model solution in an exercise, a button above it switches it to the PostgreSQL version.
Try it now
A customer wants to know what you stock in black. Plain LIKE is enough here, because SQLite ignores case for plain letters. Keep your answer in mind: in PostgreSQL the very same query finds nothing, and the next section explains why.
Task A customer on the phone wants to know what you stock in black. Show the name and price of every product with the word black anywhere in its name.
products 12 rows, 5 columns
| product_id | name | category | price | stock |
|---|---|---|---|---|
| 1 | Copy paper, 500 sheets | Paper | 4.99 | 420 |
| 2 | Blue ballpoint pens, 10-pack | Writing | 3.49 | 310 |
| 3 | Lever arch file, gray | Filing | 2.79 | 185 |
| 4 | Comfort office chair | Furniture | 189 | 12 |
| 5 | Standing desk | Furniture | 449 | 5 |
| 6 | Black ink cartridge | Printer supplies | 24.9 | 64 |
| 7 | Yellow sticky notes, 12 pads | Writing | 6.99 | 0 |
| 8 | Mono laser printer L30 | Electronics | 219 | 8 |
| 9 | 27-inch monitor | Electronics | 279 | 15 |
| 10 | Notebook A5, ruled | Paper | 5.49 | 140 |
| 11 | Black toner XL | Printer supplies | 89.9 | 22 |
| 12 | Cross-cut shredder | Electronics | 129 | 0 |
Where PostgreSQL differs
LIKE is case-sensitive: meet ILIKE
In our practice database this query finds both products, even though the names start with a capital B:
SELECT name, price
FROM products
WHERE name LIKE '%black%';
| name | price |
|---|---|
| Black ink cartridge | 24.9 |
| Black toner XL | 89.9 |
PostgreSQL’s normal text operators are case-sensitive, so the same LIKE returns no rows there. To match regardless of case, PostgreSQL offers ILIKE, an extension that is not part of the SQL standard. The portable approach is to apply lower() to the column:
-- PostgreSQL only
SELECT name, price FROM products WHERE name ILIKE '%black%';
-- runs everywhere, including the exercise above
SELECT name, price FROM products WHERE lower(name) LIKE '%black%';
The practice database does not know ILIKE and answers with an error message. Your logic is fine; SQLite simply lacks the keyword. In the exercises, use LIKE or the lower() version.
Unquoted names are folded to lower case
PostgreSQL turns table and column names without quotes into lower case, so Products, PRODUCTS and products all mean the same table. Put a name in double quotes and the exact spelling counts: "Products" is then a different table. If someone created a table with capitals inside quotes, you have to quote it that way every time. The easy rule: keep names lower case and unquoted, as in our exercises. Text values go in single quotes; double quotes always mean a name in PostgreSQL.
Dates: real date types and to_char
Our exercises store dates as text. In PostgreSQL a date column has the type date, and you can do arithmetic on it directly:
SELECT CURRENT_DATE; -- today's date
SELECT DATE '2026-06-01' + 7; -- 2026-06-08
SELECT DATE '2026-06-30' - DATE '2026-06-01'; -- 29 (days)
SELECT EXTRACT(YEAR FROM order_date) FROM orders;
SELECT to_char(order_date, 'YYYY-MM') AS order_month FROM orders;
YYYY is the year and MM the two-digit month. In the practice database you write strftime('%Y-%m', order_date) instead; to_char gets the reply “The function to_char does not exist in this practice database (SQLite).” For type conversions PostgreSQL accepts the standard CAST('2026-06-01' AS date) as well as its own shorthand '2026-06-01'::date.
Automatic IDs: IDENTITY, not AUTO_INCREMENT
CREATE TABLE categories (
category_id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
name text NOT NULL
);
With ALWAYS, PostgreSQL always assigns the number itself and only accepts your own value with OVERRIDING SYSTEM VALUE. With BY DEFAULT, a value you supply takes precedence. Older tutorials often use serial; the documentation explains that it is not a true data type but a PostgreSQL-specific shorthand, while the identity column is the SQL-standard form.
Joining text and limiting rows
Both work as they do here: last_name || ', ' || first_name and LIMIT 3 after ORDER BY. Two extras from the docs: concat() and concat_ws() ignore NULL arguments, which helps with optional fields. And LIMIT is PostgreSQL syntax that MySQL shares; the SQL-standard way is FETCH FIRST 3 ROWS ONLY, and PostgreSQL accepts both. Without ORDER BY, neither form promises which rows you get.
psql commands, pgAdmin and setup
psql is PostgreSQL’s terminal client: you type a query and see the result. On top of SQL it understands backslash commands of its own, and these are the ones people search for most:
\l -- list databases
\c shop -- connect to the database shop
\dt -- show tables
\d products -- columns and types of a table
\q -- quit psql
CREATE DATABASE shop; -- create a new database
SELECT version(); -- server version
- pgAdmin: the graphical administration and development tool, open source, for Windows, macOS and Linux. It runs as a desktop application or as a web application in the browser; you write queries in its Query Tool.
- Installing on Windows: the PostgreSQL download page points to an installer from EDB (EnterpriseDB). It installs the PostgreSQL server, pgAdmin and StackBuilder for extra tools and drivers.
- From the command line:
createdb shopcreates a database without opening psql first.
Another exercise: joining names
Here the close match between SQLite and PostgreSQL pays off: an answer written with || runs on PostgreSQL without a single change.
Task HR needs two columns from the employees table for the staff directory: first the name in the form Last, First (for example Mitchell, Karen, with a comma and a space), then the department.
employees 10 rows, 7 columns
| employee_id | first_name | last_name | department | salary | hire_date | manager_id |
|---|---|---|---|---|---|---|
| 1 | Karen | Mitchell | Management | 93600 | 2018-01-02 | NULL |
| 2 | Tom | Bradley | Sales | 62400 | 2019-04-01 | 1 |
| 3 | Julia | Reyes | Sales | 46800 | 2021-06-15 | 2 |
| 4 | Marcus | Allen | Sales | 49200 | 2020-09-01 | 2 |
| 5 | Sarah | Long | Warehouse | 39600 | 2022-02-01 | 1 |
| 6 | Felix | Turner | Warehouse | 35400 | 2024-03-18 | 5 |
| 7 | Nina | Cooper | Accounting | 52800 | 2019-10-01 | 1 |
| 8 | David | Ross | Customer service | 38400 | 2023-05-02 | 2 |
| 9 | Laura | Hughes | Customer service | NULL | 2025-09-01 | 2 |
| 10 | Paul | Ward | Accounting | 43200 | 2022-11-14 | 7 |
And one with an automatic ID
The products table numbers its own rows, like an identity column in PostgreSQL. Leave the ID out of your INSERT.
Task A new product is joining the range: the LED desk lamp in the Electronics category, price 39.90, 25 in stock. Add it to the products table. Leave out product_id; the database assigns it. After Run or Check you will see the row you added.
products 12 rows, 5 columns
| product_id | name | category | price | stock |
|---|---|---|---|---|
| 1 | Copy paper, 500 sheets | Paper | 4.99 | 420 |
| 2 | Blue ballpoint pens, 10-pack | Writing | 3.49 | 310 |
| 3 | Lever arch file, gray | Filing | 2.79 | 185 |
| 4 | Comfort office chair | Furniture | 189 | 12 |
| 5 | Standing desk | Furniture | 449 | 5 |
| 6 | Black ink cartridge | Printer supplies | 24.9 | 64 |
| 7 | Yellow sticky notes, 12 pads | Writing | 6.99 | 0 |
| 8 | Mono laser printer L30 | Electronics | 219 | 8 |
| 9 | 27-inch monitor | Electronics | 279 | 15 |
| 10 | Notebook A5, ruled | Paper | 5.49 | 140 |
| 11 | Black toner XL | Printer supplies | 89.9 | 22 |
| 12 | Cross-cut shredder | Electronics | 129 | 0 |
The lessons that matter most for PostgreSQL
- LIKE: patterns are identical, but case counts in PostgreSQL. Remember ILIKE or lower().
- String functions: || carries over one to one, and concat_ws handles empty fields.
- Date functions: PostgreSQL works with real date values, but the approach is the same.
- CASE WHEN and NULL and COALESCE: shortcuts such as IIF or IFNULL do not exist in PostgreSQL, so the standard forms are what you need.
- CTEs with WITH and window functions: especially handy for reporting in PostgreSQL, and written the same way.
- CREATE TABLE and primary and foreign keys: for building your own tables, with IDENTITY and types such as text, date and numeric.
FAQ
Is PostgreSQL free?
Yes. Its licence allows anyone to use, modify and distribute PostgreSQL at no cost, for private, commercial or academic purposes. pgAdmin is open source too.
Postgres or PostgreSQL: which is right?
Both. PostgreSQL is the current name, and according to the documentation “Postgres” is still an official project name, partly out of tradition and partly because it is easier to say.
How do I list databases and show tables in PostgreSQL?
In psql, \l lists all databases, \c name switches to one, \dt shows its tables and \d tablename describes a table. With plain SQL, CREATE DATABASE name; creates a new one.
Why does LIKE find nothing in PostgreSQL when it works here?
Because PostgreSQL compares case-sensitively and SQLite’s LIKE does not. Use ILIKE, or compare with lower(name) LIKE '%pattern%'.
Which version does this page cover?
Everything was checked against the current PostgreSQL documentation (version 18). Older versions may differ in places; SELECT version(); tells you what you are running.
Sources: PostgreSQL documentation on postgresql.org (What Is PostgreSQL?, A Brief History of PostgreSQL, Pattern Matching, String Functions, Lexical Structure, Date/Time Functions, Data Type Formatting Functions, Value Expressions, Identity Columns, Numeric Types, LIMIT and OFFSET, SELECT, psql, CREATE DATABASE, Creating a Database, System Information Functions), Windows download page on postgresql.org, pgadmin.org.