PostgreSQL timestamptz vs timestamp: Why most schemas use the wrong type
PostgreSQL offers two timestamp types — timestamp and timestamptz — both storing 8 bytes, but only timestamptz correctly records an absolute moment in time by converting values to UTC. Most databases end up with the wrong type by default because frameworks like Rails and Prisma emit the naive timestamp type unless developers explicitly override it. Unlike a mismatched varchar, a timestamp column silently produces incorrect results only at daylight saving boundaries or when a server's time zone changes, making the error hard to detect. PostgreSQL's own documentation advises against using timestamp without time zone, comparing it to a picture of a clock rather than a true point in time. Developers are advised to use timestamptz for any column recording when something happened, reserving plain timestamp only for intentional wall-clock values like store opening hours or recurring alarms.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in