Maintaining `created_at` and `updated_at` audit columns in PostgreSQL can be done without triggers. While MySQL supports an `ON UPDATE` clause for auto-updating timestamps, PostgreSQL lacks this feature. A lesser-known Postgres capability allows setting a column to its `DEFAULT` value in an `UPDATE` statement, meaning you can define `updated_at` with a default of `current_timestamp` and include `updated_at = DEFAULT` in every UPDATE query. This avoids clock-skew anomalies from application-side timestamps and is simpler than writing per-table triggers. The `RETURNING` clause can be used to retrieve the new timestamp value after the update.
Sort: