TIMESTAMPTZ (timestamp with time zone)
Last updated: 2026-11-04
TIMESTAMPTZ (timestamp with time zone)
TIMESTAMPTZ denotes an absolute instant: it is stored internally as UTC and converted to local wall time according to the session's TimeZone setting when read, so the same value renders differently per session while always meaning the same moment. It is the correct default for "when did this happen" data, and a timestamptz column with DEFAULT now() records the insertion instant automatically.
| Kind | type |
|---|---|
| Example Language | SQL |
📝 Syntax
TIMESTAMPTZ | TIMESTAMP WITH TIME ZONE —— 8 bytes, stored as UTC internally
TIMESTAMPTZ(precision) —— specifies fractional-second precision
Returns:Stores an absolute instant (UTC internally). The rendered value depends on the session TimeZone; AT TIME ZONE 'Asia/Shanghai' converts it explicitly to a given local wall time.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
id | created_at | in_shanghai | epoch_seconds | col_type
----+------------------------+---------------------+---------------+--------------------------
1 | 2024-03-15 02:30:00+00 | 2024-03-15 10:30:00 | 1710469800 | timestamp with time zone
📌 Key Points
- The input '2024-03-15 10:30:00+08' means UTC+8, which converts to 2024-03-15 02:30:00+00 — both denote the same instant.
- AT TIME ZONE 'Asia/Shanghai' returns a TIMESTAMP without zone, that is, the local wall time there.
- The SET TimeZone = 'UTC' after the first line only makes the output deterministic; it does not affect the table structure.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QWhat does TIMESTAMPTZ actually store?
AA UTC instant (microseconds since 2000-01-01). The session time zone affects only display and input parsing. No local time information is stored, so changing zones never changes the meaning of the data.
QWhy does one column render differently in different clients?
ABecause each session has its own TimeZone. Pin the output with SET TimeZone = 'UTC', set it to 'Asia/Shanghai' for business-local display, or be explicit with AT TIME ZONE in the query.