Re: now() AT TIME ZONE 'GMT';

Lists: pgsql-generalpgsql-hackers
From: Richard Emberson <emberson(at)phc(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: now() AT TIME ZONE 'GMT';
Date: 2002-04-08 23:03:34
Message-ID: 3CB221C6.CEA73711@phc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers


If I want a column to have a default TIMESTAMP of 'now' but not in PST
timezone but GMT,
is the best way of doing it the following:

change_time TIMESTAMP DEFAULT now() AT TIME ZONE 'GMT' NOT NULL,

Richard


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Richard Emberson <emberson(at)phc(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: now() AT TIME ZONE 'GMT';
Date: 2002-04-09 02:52:19
Message-ID: 25303.1018320739@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

Richard Emberson <emberson(at)phc(dot)net> writes:
> If I want a column to have a default TIMESTAMP of 'now' but not in PST
> timezone but GMT,

It strikes me that you have a conceptual error. Type TIMESTAMP (ie,
TIMESTAMP WITH TIME ZONE) *is* GMT internally; it is simply displayed
in whatever zone you've selected with SET TIMEZONE. (This is basically
the same design as Unix system clocks --- always GMT --- and the TZ
environment variable.) If you are trying to force it to a different
timezone then you are misusing it.

Type TIMESTAMP WITHOUT TIME ZONE doesn't have any concept of time zone
--- it's just a stated date and time with no particular zone reference.
If you apply the AT TIME ZONE operator to a TIMESTAMP WITH TIME ZONE
value, what happens is the internal GMT value is rotated to the
specified zone and then the output is labeled as type TIMESTAMP WITHOUT
TIME ZONE, preventing any further automatic zone rotations. If you
coerce this back to TIMESTAMP WITH TIME ZONE, the implicitly assigned
zone is your local zone --- ie, your local zone is subtracted off again
to produce a supposed GMT value --- with entirely nonsensical results.

It wasn't clear to me exactly what you wanted to accomplish, but
applying AT TIME ZONE to something you are going to store in a TIMESTAMP
almost certainly isn't it. My guess is that what you really want is
plain old unadorned "TIMESTAMP DEFAULT now()".

If you want to deliberately suppress time zone awareness, TIMESTAMP
WITHOUT TIME ZONE is the way to go. If you want any awareness of zones,
you almost certainly want TIMESTAMP WITH TIME ZONE --- and just let the
system do what it wants to do, don't try to force some other approach.

regards, tom lane


From: Thomas Lockhart <lockhart(at)fourpalms(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Richard Emberson <emberson(at)phc(dot)net>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [GENERAL] now() AT TIME ZONE 'GMT';
Date: 2002-04-09 06:22:53
Message-ID: 3CB288BD.DEBCD0B6@fourpalms.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

(on -hackers)

> If you apply the AT TIME ZONE operator to a TIMESTAMP WITH TIME ZONE
> value, what happens is the internal GMT value is rotated to the
> specified zone and then the output is labeled as type TIMESTAMP WITHOUT
> TIME ZONE, preventing any further automatic zone rotations.

Hmm. That is how it probably *should* work, but at the moment the
timestamptz_zone() function actually outputs a character string! That is
a holdover from previous versions which did not have a "no zone"
timestamp; it would seem now to be more appropriate to output a no-zone
timestamp.

I'll look at changing this in my upcoming patch set...

- Thomas


From: Richard Emberson <emberson(at)phc(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: now() AT TIME ZONE 'GMT';
Date: 2002-04-09 15:14:08
Message-ID: 3CB30540.2151BD78@phc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

Tom Lane wrote:

> Richard Emberson <emberson(at)phc(dot)net> writes:
> > If I want a column to have a default TIMESTAMP of 'now' but not in PST
> > timezone but GMT,
>
> It strikes me that you have a conceptual error. Type TIMESTAMP (ie,

I guess so. So it is during the retrieval of a timestamp using jdbc, where
the timestamp
is converted into a java.sql.Timestamp that it gets converted to a local
timezone.
So I will have to use the jdbc access method that preserves (actually where
one can
set the desired timezone) the timezone.

Richard