Skip to Content
193 results
0 likes
Fix "column does not exist" Level: Beginner

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.

0 likes
Import a CSV With \copy Level: Beginner

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.

0 likes
Verify a PostgreSQL Practice Database and Its Persistence Level: Beginner

Identify an isolated practice database, record its cluster and marker, and verify persistence through restart and container replacement before exact cleanup.

0 likes
Keep Rows With No Match Using LEFT JOIN Level: Beginner

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.

0 likes
Select Only the Columns You Need Level: Beginner

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.

0 likes
Run UPDATE and DELETE in a Transaction First Level: Beginner

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.

0 likes
Why = NULL Returns Nothing Level: Beginner

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.

0 likes
Add a CHECK Constraint to a Table That Has Data Level: Intermediate

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.

0 likes
Delete Duplicate Rows and Keep One Level: Intermediate

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.

0 likes
Fix "must appear in the GROUP BY clause" Level: Intermediate

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.

0 likes
Get the Latest Row per Group With DISTINCT ON Level: Intermediate

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.

0 likes
Paginate Without OFFSET Level: Intermediate

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.