sql / intermediate
Snippet
Preserving Temporal Integrity with TIMESTAMP WITH TIME ZONE
The ANSI standard TIMESTAMP WITH TIME ZONE data type stores date and time values alongside UTC offset information. This guarantees that temporal data remains unambiguous across different geographical time zones and daylight saving adjustments.
snippet.sql
sql
1
2
3
4
5
6
CREATE TABLE global_events (event_id INT NOT NULL PRIMARY KEY,event_name VARCHAR(100) NOT NULL,created_at TIMESTAMP WITH TIME ZONE NOT NULL,scheduled_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP);
Breakdown
1
CREATE TABLE global_events (
Defines a table structure intended for storing distributed system events.
2
event_id INT NOT NULL PRIMARY KEY,
Sets the surrogate primary key column that uniquely identifies every event record.
3
event_name VARCHAR(100) NOT NULL,
Stores descriptive text identifying the event type or descriptive title.
4
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
Specifies a mandatory timestamp column including timezone offset data.
5
scheduled_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
Provides an optional future schedule timestamp defaulting to the current system transaction timestamp with offset.
6
);
Terminates the table declaration statement.