timestamptz Versus timestamp Storage Semantics
The same literal stores differently: timestamp without time zone keeps the wall clock verbatim, timestamptz normalizes to UTC and renders per session zone.
Code
SET TimeZone = 'UTC'; -- 固定会话时区,输出可复现
CREATE TABLE stamps (
id int GENERATED ALWAYS AS IDENTITY,
wall_clock timestamp WITHOUT TIME ZONE, -- 只存字面钟点
absolute timestamptz -- 内部一律 UTC,渲染跟随会话时区
);
-- 同一个带偏移的字面量:timestamptz 吸收 +02 换算,timestamp 直接丢弃偏移
INSERT INTO stamps (wall_clock, absolute)
VALUES ('2026-06-21 10:00:00+02', '2026-06-21 10:00:00+02');
SELECT wall_clock, absolute FROM stamps;
-- wall_clock = 2026-06-21 10:00:00 (字面值原样保留)
-- absolute = 2026-06-21 08:00:00+00(先归一 UTC,再按会话时区渲染)
-- localtimestamp 是 now() 的"无时区"版本,同样受会话时区影响
SELECT now() AS with_zone, localtimestamp AS without_zone;How it works
What runs here is SELECT / INSERT / CREATE — stamps are the objects involved.
Breaking the statements into their working parts: a GENERATED ALWAYS/GENERATED BY clause that computes the column value.
Putting it to use
Run the statement against the stamps table.
Core lines
CREATE TABLE stamps (
id int GENERATED ALWAYS AS IDENTITY,
wall_clock timestamp WITHOUT TIME ZONE, -- 只存字面钟点
absolute timestamptz -- 内部一律 UTC,渲染跟随会话时区
);
INSERT INTO stamps (wall_clock, absolute)
VALUES ('2026-06-21 10:00:00+02', '2026-06-21 10:00:00+02');
SELECT now() AS with_zone, localtimestamp AS without_zone;
Interactive Tools for This Topic
PostgreSQL EXPLAIN AnalyzerAnalyze PostgreSQL EXPLAIN ANALYZE text or FORMAT JSON plans locally to flag Seq Scans, slow nodes, row misestimates, disk sorts, and index hints.SQL DDL to TypeScript ConverterConvert SQL CREATE TABLE DDL statements into strict TypeScript interfaces with nullable, array, enum, JSONB, and Date or ISO string column mappings.Multi-Mode Escape & Unescape CodecEscape and unescape strings safely across JSON, JavaScript, SQL single-quoted literals, POSIX shell single quotes, and RFC 4180 CSV cells in your browser.SQL FormatterReformat SQL by uppercasing reserved words and breaking lines before SELECT, FROM, WHERE, and other clauses.
FAQ
- Name the tables involved in this file.
- `stamps`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.