From 1efef2763236ab42d71a34ed90a1a31579443b9d Mon Sep 17 00:00:00 2001 From: Yorhel Date: Thu, 6 Aug 2009 17:44:11 +0200 Subject: Use timestamptz data type instead of timestamp It took me a while to figure out that the "timestamp with timezone" PostgreSQL type doesn't actually store the time zone, it simply stores and calculates on UTC, and only converts it to the connection time zone in the formatting stage before sending it to the SQL client. When working with date/times in PgSQL, the NOW() (and related) functions return a timestamp with time zone. Upon converting that to a timestamp without time zone type, the current timezone setting is used. Meaning that comparing a column of type timestamp without timezone to NOW() will only work if all data in the columns is stored in the same timezone as that of the current connection, which in turn means that changing this setting at any point will cause all data in timestamp without timezone columns to be incorrectly interpreted. I often praise PostgreSQL for their comprehensive documentation, but they could've pointed this out more clearly... --- util/dump.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'util/dump.sql') diff --git a/util/dump.sql b/util/dump.sql index bdff5c6b..3a470102 100644 --- a/util/dump.sql +++ b/util/dump.sql @@ -26,7 +26,7 @@ CREATE TABLE anime ( type smallint, title_romaji, title_kanji, - lastfetch timestamp + lastfetch timestamptz ); -- changes @@ -165,7 +165,7 @@ CREATE TABLE screenshots ( CREATE TABLE sessions ( uid integer NOT NULL, token bytea NOT NULL, - expiration timestamp NOT NULL DEFAULT (now() + '1 year'::interval), + expiration timestamptz NOT NULL DEFAULT (now() + '1 year'::interval), PRIMARY KEY (uid, token) ); -- cgit v1.2.3