···2-- This column stores the older of publishedAt (from JSON data) or indexed_at
3-- Used for sorting feeds chronologically by when content was actually published
4005ALTER TABLE documents
6ADD COLUMN sort_date timestamptz GENERATED ALWAYS AS (
7 LEAST(
8- COALESCE((data->>'publishedAt')::timestamptz, indexed_at),
9 indexed_at
10 )
11) STORED;
···2-- This column stores the older of publishedAt (from JSON data) or indexed_at
3-- Used for sorting feeds chronologically by when content was actually published
45+-- Note: We use ::timestamp AT TIME ZONE 'UTC' to make the expression immutable
6+-- (direct ::timestamptz cast is not immutable as it depends on session timezone)
7ALTER TABLE documents
8ADD COLUMN sort_date timestamptz GENERATED ALWAYS AS (
9 LEAST(
10+ COALESCE((data->>'publishedAt')::timestamp AT TIME ZONE 'UTC', indexed_at),
11 indexed_at
12 )
13) STORED;