Profile Picture

Monotonic Last Modified Columns in Postgres

December 2nd, 2024

Tracking a record’s last modified time is a common application requirement. In Postgres, a typical implementation might look like this, using a BEFORE UPDATE trigger on a last_modified_at column:

CREATE TABLE foo (
    id SERIAL PRIMARY KEY,
    name TEXT,
    last_modified_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE OR REPLACE FUNCTION update_last_modified_at()
RETURNS TRIGGER AS $$
BEGIN
    NEW.last_modified_at = now();
    RETURN NEW;
END;
$$ LANGUAGE 'plpgsql';

CREATE TRIGGER update_last_modified_at_trigger
BEFORE UPDATE ON foo
FOR EACH ROW
EXECUTE PROCEDURE update_last_modified_at();

This works in most cases, but breaks an assumption that’s likely made by the application: last_modified_at isn’t necessarily monotonically increasing, even if the system clock is. This can cause problems when the application uses last_modified_at as a watermark for processing changes.

Read More →

Temperature and Speed—Redux

November 18th, 2024
Temperature and Speed—Redux

Almost four years ago, I wrote a post about the relationship between temperature and speed, finding a linear relationship on 30m fly times with an R² of 0.21. I’ve kept tracking every rep since then—instead of 150 data points, I now have almost a thousand. I’ve also gotten more sophisticated with how I estimate fly and acceleration times from single reps that deserves its own blogpost. For now, what’s important is that across this four-year dataset, I have 642 30m acceleration reps and 451 10m fly reps, with temperatures ranging from 14° to 95° F.

Read More →

Next Season

August 17th, 2023

After a disappointing end to my season, I spent some time reflecting on what went wrong and what I can do better this year. The obvious acute answer is the back injury I suffered in March; the other obvious answer is the lack of racing between May and July to keep me sharp.

Read More →

Failure

July 24th, 2023

Most of the posts on this blog are about success. I write about my PRs, my wins, and my accomplishments. I write about the things that I’m proud of.

When I write about my failures, I write about setbacks. I write about how they are just temporary roadblocks that make my eventual success that much sweeter.

But sometimes failure is just failure.

Read More →
Next →