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_idnamecategorypricestock
1Copy paper, 500 sheetsPaper4.99420
2Blue ballpoint pens, 10-packWriting3.49310
3Lever arch file, grayFiling2.79185
4Comfort office chairFurniture18912
5Standing deskFurniture4495
6Black ink cartridgePrinter supplies24.964
7Yellow sticky notes, 12 padsWriting6.990
8Mono laser printer L30Electronics2198
927-inch monitorElectronics27915
10Notebook A5, ruledPaper5.49140
11Black toner XLPrinter supplies89.922
12Cross-cut shredderElectronics1290

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%';
nameprice
Black ink cartridge24.9
Black toner XL89.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 shop creates 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_idfirst_namelast_namedepartmentsalaryhire_datemanager_id
1KarenMitchellManagement936002018-01-02NULL
2TomBradleySales624002019-04-011
3JuliaReyesSales468002021-06-152
4MarcusAllenSales492002020-09-012
5SarahLongWarehouse396002022-02-011
6FelixTurnerWarehouse354002024-03-185
7NinaCooperAccounting528002019-10-011
8DavidRossCustomer service384002023-05-022
9LauraHughesCustomer serviceNULL2025-09-012
10PaulWardAccounting432002022-11-147

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_idnamecategorypricestock
1Copy paper, 500 sheetsPaper4.99420
2Blue ballpoint pens, 10-packWriting3.49310
3Lever arch file, grayFiling2.79185
4Comfort office chairFurniture18912
5Standing deskFurniture4495
6Black ink cartridgePrinter supplies24.964
7Yellow sticky notes, 12 padsWriting6.990
8Mono laser printer L30Electronics2198
927-inch monitorElectronics27915
10Notebook A5, ruledPaper5.49140
11Black toner XLPrinter supplies89.922
12Cross-cut shredderElectronics1290

The lessons that matter most for PostgreSQL

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.

Next up: the first lesson

The course starts with your first query and takes you through JOIN, GROUP BY, CTEs and window functions. Nearly all of it is written the same way in PostgreSQL.

Start with the basics

Write to us

Choose language

Select your preferred language