···22-- This column stores the older of publishedAt (from JSON data) or indexed_at
33-- Used for sorting feeds chronologically by when content was actually published
4455+-- Note: We use ::timestamp AT TIME ZONE 'UTC' to make the expression immutable
66+-- (direct ::timestamptz cast is not immutable as it depends on session timezone)
57ALTER TABLE documents
68ADD COLUMN sort_date timestamptz GENERATED ALWAYS AS (
79 LEAST(
88- COALESCE((data->>'publishedAt')::timestamptz, indexed_at),
1010+ COALESCE((data->>'publishedAt')::timestamp AT TIME ZONE 'UTC', indexed_at),
911 indexed_at
1012 )
1113) STORED;