Six PostgreSQL one-liners that come up over and over in everyday work — the kind of thing you Google for the third time and then finally paste into a notes file. Filtering rows from today onward with now()::date, resetting a sequence with setval('users_id_seq', 5), and getting human-readable sizes from pg_size_pretty(pg_database_size(...)) and pg_total_relation_size(...) for tables.
The full post also covers deduping rows with a ROW_NUMBER() OVER (PARTITION BY ...) window inside a DELETE, and reassigning a table's owner with ALTER TABLE ... OWNER TO. Nothing exotic — just the snippets worth keeping in a scratchpad so you don't have to rederive them at 11pm.
Originally published at andreasbergstrom.dev — read the full post there.
Top comments (0)