Make updated_at refresh itself
Backend devs regularly forget to set updated_at = NOW() by hand after an UPDATE, and the field rots — nobody knows when a row was last touched. The fix is a trigger on the table that sets the current time before every update on its own.
Build a notes table with id (primary key), body (text), and updated_at (timestamp with timezone, defaulting to now). Define a function touch_updated_at that returns a row with updated_at refreshed, and a trigger named notes_touch that fires before every row update on notes and calls this function. After the setup any UPDATE on notes should automatically bump updated_at to the current time.
Expected output sample
This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.
| tgname |
|---|
| notes_touch |
Sign in to see submission history
Sign inSign in to use AI Mentor
Sign inNo starting schema
This task starts with no tables — you'll create them via CREATE TABLE.