Skip to content

SQL · correctness

enforce-timestamptz

sql:enforce-timestamptz

TIMESTAMP without TIME ZONE — use TIMESTAMPTZ.

Code
SARJ101
Default
error
Fix
none
Languages
sql

Why

Naive timestamps discard offset context and make cross-time-zone comparisons ambiguous.

Fix

Declare persisted instants as TIMESTAMPTZ or TIMESTAMP WITH TIME ZONE.

Before / after

Executed by this rule’s unit tests.

Before

Naive timestamp column

migrations/001_orders.sql · focus
CREATE TABLE orders (created_at TIMESTAMP NOT NULL);

After

Timestamp with time-zone semantics

migrations/001_orders.sql · focus
CREATE TABLE orders (created_at TIMESTAMPTZ NOT NULL);