timestamptz and time zones
it stores an instant, not a zone. and the hour in march that never happened.
- address
- everything.types.timestamptz
- part
- part 6, types and values
- chapter
- chapter 5 of 11
- reading time
- 8 min
a timestamptz stores an instant, a point on the world's one timeline, as UTC. it doesn't store a time zone. the session's TimeZone setting decides how it's read from text and printed back. a plain timestamp is a wall-clock reading with no zone at all.
AT TIME ZONE converts between the two, and a clock change makes some wall times happen twice and others never.
the picture
you know how "with time zone" sounds like the value carries its zone around? it doesn't. timestamp with time zone stores no zone at all. it stores a moment, and prints it in whatever zone your session says. the type with "without time zone" in its name is the one that's missing something.
think of a photo of the sky at one instant. ask people in four cities what their clock said when it was taken, and you get four answers, all correct. the photo is the timestamptz. the four clocks are four TimeZone settings printing it.
- 1SET TimeZone = 'Europe/Paris';
- 2SELECT created_at FROM customers WHERE id = 12;
paris had just changed its clocks: at 01:00 UTC the wall clock jumped from 02:00 to 03:00, so half an hour later it says 03:30, and the offset is +02 where it was +01 an hour before.
it stores an instant
here's that customer, under two settings. the value doesn't move; the text does:
SET TimeZone = 'UTC';
SELECT name, created_at FROM customers WHERE id = 12;
SET TimeZone = 'Asia/Kolkata';
SELECT name, created_at FROM customers WHERE id = 12;| nametext | created_attimestamptz |
|---|---|
| Ravi Kumar | 2026-03-29 01:30:00+00 |
| nametext | created_attimestamptz |
|---|---|
| Ravi Kumar | 2026-03-29 07:00:00+05:30 |
01:30 in UTC, 07:00 in Kolkata, the same 8 bytes on disk. the zone is applied on the way in, when text becomes a timestamptz, and on the way out, when it's printed:
- in: if the text has an offset or a zone name (
+05:30,Europe/Paris), that's used. if not, the session's TimeZone is. - out: always the session's TimeZone, with the offset printed after it.
a plain timestamp skips both steps. and it doesn't complain if you hand it an offset; it just drops it:
SET TimeZone = 'UTC';
SELECT timestamp '2026-03-29 01:30+05:30' AS plain,
timestamptz '2026-03-29 01:30+05:30' AS with_tz;| plaintimestamp | with_tztimestamptz |
|---|---|
| 2026-03-29 01:30:00 | 2026-03-28 20:00:00+00 |
the timestamp kept the wall clock and threw the +05:30 away. the timestamptz used it to find the instant, 20:00 UTC the evening before.
so: timestamptz for things that happened (an order, a login, an event), because what you want later is "when", and you'll want to print it in whichever zone the reader is in. a plain timestamp only for wall-clock times that aren't instants yet: "the shop opens at 09:00, local". a birthday is a date.
AT TIME ZONE, both ways
AT TIME ZONE is the converter, and it goes in both directions depending on what you hand it. that's the classic confusion: the same words, opposite jobs.
- 1SET TimeZone = 'UTC';
- 2SELECT timestamptz '2026-03-29 01:30+00' AT TIME ZONE 'Asia/Kolkata' AS result,
- 3 pg_typeof(timestamptz '2026-03-29 01:30+00' AT TIME ZONE 'Asia/Kolkata') AS type;
| resulttimestamp | typeregtype |
|---|---|
| 2026-03-29 07:00:00 | timestamp without time zone |
timestamptz AT TIME ZONE: an instant in, the wall clock in that zone out, as a plain timestamp.
SET TimeZone = 'UTC';
SELECT timestamp '2026-03-29 01:30' AT TIME ZONE 'Asia/Kolkata';a handy reading: instant AT TIME ZONE z asks "what did the clocks in z say?", and wall_clock AT TIME ZONE z asks "when was it, if that was a clock in z?"
the hour that never happened
on 2026-03-29 at 01:00 UTC, paris moved its clocks from 02:00 straight to 03:00. a paris wall time between 02:00 and 03:00 doesn't exist that day. type one in anyway:
| typed | stored | in_utc |
|---|---|---|
| 2026-03-29 01:30 | 2026-03-29 01:30:00+01 | 2026-03-29 00:30:00 |
| 2026-03-29 02:00 | 2026-03-29 03:00:00+02 | 2026-03-29 01:00:00 |
| 2026-03-29 02:30 | 2026-03-29 03:30:00+02 | 2026-03-29 01:30:00 |
| 2026-03-29 03:00 | 2026-03-29 03:00:00+02 | 2026-03-29 01:00:00 |
| 2026-03-29 03:30 | 2026-03-29 03:30:00+02 | 2026-03-29 01:30:00 |
no error, no warning. 02:30 becomes 03:30, and two different inputs now mean the same moment. if you store wall times typed by people, validate them in the zone they meant, or store the instant they meant, not what they typed.
in october it goes the other way. on 2026-10-25 paris sets its clocks back from 03:00 to 02:00, so 02:30 happens twice. postgres picks the second one, after the change, at +01:
SET TimeZone = 'Europe/Paris';
SELECT timestamptz '2026-10-25 02:30' AS typed,
timestamptz '2026-10-25 00:30+00' AS first_0230,
timestamptz '2026-10-25 01:30+00' AS second_0230;| typedtimestamptz | first_0230timestamptz | second_0230timestamptz |
|---|---|---|
| 2026-10-25 02:30:00+01 | 2026-10-25 02:30:00+02 | 2026-10-25 02:30:00+01 |
the first 02:30 can only be written with its offset (02:30+02), or as UTC.
SET TimeZone = 'Europe/Paris';
SELECT timestamptz '2026-03-28 12:00' + interval '1 day',
timestamptz '2026-03-28 12:00' + interval '24 hours';the interval's day field and its time field are kept apart for exactly this:
SET TimeZone = 'Europe/Paris';
SELECT timestamptz '2026-03-28 12:00' + interval '1 day' AS plus_day,
timestamptz '2026-03-28 12:00' + interval '24 hours' AS plus_24h;| plus_daytimestamptz | plus_24htimestamptz |
|---|---|
| 2026-03-29 12:00:00+02 | 2026-03-29 13:00:00+02 |
1 day means "same wall-clock time tomorrow", in the session's zone, so it lands at 12:00 after only 23 real hours. 24 hours means 24 hours, so the clock reads 13:00. both are right, for different questions.
the day depends on where you stand
anything that turns an instant into a calendar day, ::date, date_trunc('day', ...), extract(day ...), does it in the session's zone. the same customers, counted per day, in two places:
SET TimeZone = 'UTC';
SELECT count(*) AS signed_up_on_the_29th FROM customers WHERE created_at::date = '2026-03-29';
SET TimeZone = 'America/New_York';
SELECT count(*) AS signed_up_on_the_29th FROM customers WHERE created_at::date = '2026-03-29';| signed_up_on_the_29thint8 |
|---|
| 1 |
| signed_up_on_the_29thint8 |
|---|
| 0 |
1 in UTC, 0 in new york, where Ravi signed up on the 28th. that's why an index on created_at::date isn't allowed: its value depends on a setting. (expression indexes shows the error and the fix: name the zone in the expression.) for daily reports, decide whose days they are and say it: (created_at AT TIME ZONE 'Europe/Paris')::date. generate_series has the same issue with daily steps, and a fourth argument for the zone (generate_series).
keylines
- timestamptz stores an instant, not a zone. TimeZone only changes how it's read and printed.
- timestamp is a wall clock with no zone, and it silently drops an offset you give it.
- instant AT TIME ZONE z gives z's wall clock; wall clock AT TIME ZONE z gives the instant.
- a clock change skips some wall times and repeats others, and postgres doesn't complain.
- turning an instant into a day needs a zone. say which one.