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
CREATE TABLE orders (created_at TIMESTAMP NOT NULL);
After
Timestamp with time-zone semantics
CREATE TABLE orders (created_at TIMESTAMPTZ NOT NULL);