Programming
Programming tutorials for people who want code that actually runs, not code that only looks right. Pick a language, start at the beginning, and don't skip the basics. They are where most problems come from.
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.
Turn one row per status into one column per status with aggregate FILTER and compare it with CASE. After this, you can build a small pivot table without an extension.
Add a running total with SUM and OVER, restart it for each group and avoid the default-frame surprise when dates tie. After this, a cumulative column is one line and not a self-join.
Compare a query and its CTE rewrite in both directions with EXCEPT ALL, including duplicate and NULL rows that a plain set comparison can miss.
Choose timestamptz for a moment in time and see what the session time zone and AT TIME ZONE change. After this, the same moment shows correctly for every reader.
Rank rows inside each group and keep the first three, then decide what to do with ties and compare the LATERAL version. After this, you can pick the top rows per category and know what happens when two are equal.
Insert a row or update the one that is already there in a single statement, using the conflict target, DO NOTHING, DO UPDATE and the EXCLUDED row. After this, a repeated import updates rows instead of failing or duplicating them.