1 / 8 · Book 15 · Your First SELECT -- Reading the Source of Truth · drill: interview Q&A⊞ allnext →Get the book →
1.7Verify Timestamps
Timestamps are a frequent source of bugs: wrong timezone, not updating on modification, impossible dates.
-- Check that updated_at changes on modification
SELECT updated_at > created_at AS was_modified
FROM users
WHERE id = 123;
-- Expected: true (if user was updated)
-- Check that timestamps are reasonable (not in the future, not from 1970)
SELECT *
FROM orders
WHERE created_at > NOW()
OR created_at < '2020-01-01';
-- Expected: no rows (no invalid timestamps)