sql / intermediate
Snippet
Normalizing Timezone Operations with Standard Timestamp Types
ANSI SQL provides TIMESTAMP WITH TIME ZONE to handle global time representation consistently. Storing temporal data with explicitly declared timezone offsets prevents ambiguities across localized client connections.
snippet.sql
sql
1
2
3
4
5
CREATE TABLE audit_logs (log_id INTEGER PRIMARY KEY,action_description VARCHAR(255) NOT NULL,created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL);
Breakdown
1
CREATE TABLE audit_logs (
Defines a new relational storage structure named audit_logs.
2
log_id INTEGER PRIMARY KEY,
Declares an integer unique identifier column as the table primary key.
3
created_at TIMESTAMP WITH TIME ZONE
Specifies a data type that retains both date, time, and explicit UTC offset metrics.
4
DEFAULT CURRENT_TIMESTAMP NOT NULL
Automatically records the server system timestamp at row insertion time.