// dates & times reference

SQL TIMESTAMP WITH LOCAL TIME ZONE

A type that stores the instant normalized to UTC/database zone but always displays it converted to the querying session's zone.

類別
Dates & times
Returns
timestamp with local time zone
In this category
109 of 121

語法

TIMESTAMP WITH LOCAL TIME ZONE

引擎支援

引擎Support備註
SQL Server Not built in No built-in equivalent.
PostgreSQL Different name or syntax timestamptz renders per session via the session zone; closest behaviour
MySQL Not built in No built-in equivalent.
SQLite Not built in No built-in equivalent.
Oracle 是 this type: automatic session-zone rendering

範例

Oracle

CREATE TABLE logins (at TIMESTAMP WITH LOCAL TIME ZONE);

Oracle

ALTER SESSION SET TIME_ZONE = 'UTC'; SELECT at FROM logins;  -- shown in UTC

小知識

  • There is no visible zone on the value: display conversion is automatic and depends entirely on ALTER SESSION SET TIME_ZONE, which makes 'what did I insert?' answers session-dependent.
  • It cannot be a named-zone-aware value: no way to ask for the original offset back. If you must keep the user's zone, use TIMESTAMP WITH TIME ZONE or a separate zone column.
  • PostgreSQL's timestamptz behaves the same way in practice: it stores UTC and renders in the zone set by SET TIME ZONE.

Questions about TIMESTAMP WITH LOCAL TIME ZONE

LOCAL TIME ZONE vs WITH TIME ZONE?

WITH keeps the offset you supplied and can return it; WITH LOCAL stores in the database's zone and always renders in the session's. LOCAL is the display-friendly, zone-invisible variant.

Why do my times differ between two sessions?

That is the type working: each session sees its own wall time. Pin the session zone or CAST to UTC for stable exports.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: PostgreSQL, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.