Timestamp AT LOCAL Session Zone Conversion
Convert timestamptz and naive timestamp against the current session TimeZone using PostgreSQL 17 AT LOCAL without hardcoding zone strings.
Code
BEGIN;
SET LOCAL TIME ZONE 'UTC';
SELECT
TIMESTAMPTZ '2026-11-24 12:00:00+00' AT LOCAL AS wall_in_utc,
pg_typeof(TIMESTAMPTZ '2026-11-24 12:00:00+00' AT LOCAL) AS result_type;
-- AT LOCAL reads the active session TimeZone dynamically (PostgreSQL 17+)
SET LOCAL TIME ZONE 'America/New_York';
SELECT
TIMESTAMPTZ '2026-11-24 12:00:00+00' AT LOCAL AS ny_wall_clock,
TIMESTAMP '2026-11-24 07:00:00' AT LOCAL AS ny_to_timestamptz;
SET LOCAL TIME ZONE 'Asia/Tokyo';
SELECT
TIMESTAMPTZ '2026-11-24 12:00:00+00' AT LOCAL AS tokyo_wall_clock,
TIMESTAMP '2026-11-24 07:00:00' AT LOCAL AS tokyo_to_timestamptz;
COMMIT;Runtime mechanics — Timestamp AT LOCAL Session Zone Conversion
Each block opens inside a single BEGIN / COMMIT transaction and scopes zone changes with SET LOCAL TIME ZONE, switching from UTC to America/New_York and Asia/Tokyo before evaluating AT LOCAL.
Applying AT LOCAL to a TIMESTAMPTZ literal produces a wall-clock TIMESTAMP in the active session zone (wall_in_utc, ny_wall_clock, tokyo_wall_clock), checked directly with pg_typeof, whereas applying AT LOCAL to a naive TIMESTAMP attaches the current zone offset to yield a TIMESTAMPTZ (ny_to_timestamptz, tokyo_to_timestamptz).
Key statements
SELECT
TIMESTAMPTZ '2026-11-24 12:00:00+00' AT LOCAL AS wall_in_utc,
pg_typeof(TIMESTAMPTZ '2026-11-24 12:00:00+00' AT LOCAL) AS result_type;
SELECT
TIMESTAMPTZ '2026-11-24 12:00:00+00' AT LOCAL AS tokyo_wall_clock,
TIMESTAMP '2026-11-24 07:00:00' AT LOCAL AS tokyo_to_timestamptz;
SELECT
TIMESTAMPTZ '2026-11-24 12:00:00+00' AT LOCAL AS ny_wall_clock,
TIMESTAMP '2026-11-24 07:00:00' AT LOCAL AS ny_to_timestamptz;
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.A/B Test Sample Size CalculatorCalculate required per-variant sample size and experiment duration for two-proportion A/B tests from baseline conversion, MDE, alpha, and statistical power.CSS Unit ConverterConvert a length between px, rem, em, pt, pc, in, cm, mm, and percent using a configurable root font size, following the 96dpi CSS definition.
Report a problem with this exampleOpens a pre-filled issue on GitHub.