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.

SqlData Integrity

Code

snippet
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

FAQ

Name the tables involved in this file.
`stamps`.