Change EXTRACT(EPOCH FROM timestamp) so that a timestamp without time zone
is assumed to be in local time, not GMT. This improves consistency with other operations, which all assume local timezone when it matters. Per bug #897.
This commit is contained in:
parent
3d1a1e85cf
commit
191ef2b407
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.78 2003/02/22 05:57:45 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/timestamp.c,v 1.79 2003/02/27 21:36:58 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -2865,13 +2865,26 @@ timestamp_part(PG_FUNCTION_ARGS)
|
|||||||
switch (val)
|
switch (val)
|
||||||
{
|
{
|
||||||
case DTK_EPOCH:
|
case DTK_EPOCH:
|
||||||
|
{
|
||||||
|
int tz;
|
||||||
|
TimestampTz timestamptz;
|
||||||
|
|
||||||
|
/* convert to timestamptz to produce consistent results */
|
||||||
|
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
|
||||||
|
elog(ERROR, "Unable to convert TIMESTAMP to TIMESTAMP WITH TIME ZONE (tm)");
|
||||||
|
|
||||||
|
tz = DetermineLocalTimeZone(tm);
|
||||||
|
|
||||||
|
if (tm2timestamp(tm, fsec, &tz, ×tamptz) != 0)
|
||||||
|
elog(ERROR, "Unable to convert TIMESTAMP to TIMESTAMP WITH TIME ZONE");
|
||||||
|
|
||||||
#ifdef HAVE_INT64_TIMESTAMP
|
#ifdef HAVE_INT64_TIMESTAMP
|
||||||
result = ((timestamp - SetEpochTimestamp()) / 1000000e0);
|
result = ((timestamptz - SetEpochTimestamp()) / 1000000e0);
|
||||||
#else
|
#else
|
||||||
result = timestamp - SetEpochTimestamp();
|
result = timestamptz - SetEpochTimestamp();
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case DTK_DOW:
|
case DTK_DOW:
|
||||||
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
|
if (timestamp2tm(timestamp, NULL, tm, &fsec, NULL) != 0)
|
||||||
elog(ERROR, "Unable to encode TIMESTAMP");
|
elog(ERROR, "Unable to encode TIMESTAMP");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user