Tutorials
Practical tutorials for the work we actually do. Pick one, read it in order, and apply it.
Find the cause of the column does not exist error from the five usual ones: a typo, double quotes, an alias in WHERE, a quoted name and a missing table. After this, you can fix it in a minute instead of changing the table.
Load a CSV file into a table with the psql command copy, and read the two errors you will meet first. After this, you can import a file without writing INSERT statements.
Identify an isolated practice database, record its cluster and marker, and verify persistence through restart and container replacement before exact cleanup.
Keep customers who have no orders with LEFT JOIN, find them with IS NULL and avoid the WHERE that turns the join back into an inner join. After this, a missing match no longer removes a row from your result.
Replace SELECT * with the columns you need and see what a new column does to a query that uses the star. After this, your saved queries stop changing when the table does.
Run an UPDATE or DELETE inside a transaction, check the row count and roll back if it is wrong. After this, a missing WHERE no longer costs you the data.
See why a comparison with NULL returns no rows and fix it with IS NULL, IS DISTINCT FROM or COALESCE. After this, your WHERE clauses stop dropping rows with missing values.
Find the rows that break the rule, fix them, then add the constraint as NOT VALID and validate it. After this, you can add a rule to a table that already has data without the command failing.
Number the copies with ROW_NUMBER, preview the rows that would go, delete them inside a transaction and add a UNIQUE rule. After this, one copy of each row survives and the duplicates cannot come back.
Read the error, then fix it the right way: group by the column, aggregate it or move the aggregate into a subquery. After this, you know which fix keeps your numbers correct.
Keep one row per group in the order you choose with the PostgreSQL DISTINCT ON clause, and compare it with the standard ROW_NUMBER version. After this, the latest order per customer is one query.
Page through a table with keyset pagination: filter on the last row you showed and add a tie-breaker. After this, a later page costs the same as the first and rows do not repeat or vanish between pages.