Skip site navigation (1) Skip section navigation (2)

BUG #1617: TIME WITH TIME ZONE comparison is partially broken

From: "Dennis Vshivkov" <walrus(at)amur(dot)ru>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1617: TIME WITH TIME ZONE comparison is partially broken
Date: 2005-04-22 11:08:45
Message-ID: 20050422110845.7E2CFF13AD@svr2.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-bugs
The following bug has been logged online:

Bug reference:      1617
Logged by:          Dennis Vshivkov
Email address:      walrus(at)amur(dot)ru
PostgreSQL version: 7.4.6, 8.0.1
Operating system:   Debian GNU/Linux, kernel 2.4
Description:        TIME WITH TIME ZONE comparison is partially broken
Details: 

SELECT MAX(time) FROM (
  SELECT '04:00:01+02'::TIMETZ
  UNION
  SELECT '05:00:00+03'::TIMETZ
) AS tbl(time);
     max
-------------
 05:00:00+03
(1 row)

[8.0.1|src/backend/utils/adt/date.c] timetz_cmp_internal():

    double      t1,
                t2;

    /* Primary sort is by true (GMT-equivalent) time */
    t1 = time1->time + time1->zone;
    t2 = time2->time + time2->zone;

    if (t1 > t2)
        return 1;
    if (t1 < t2)
        return -1;

This code is only valid when HAVE_INT64_TIMESTAMP is NOT the case.  When it
is (in Debian builds, see versions below), seconds (->zone) are added to
microseconds (->time), which makes no sense.  I checked Release Notes for
8.0.2, they don't seem to mention this bug.

SELECT version():
PostgreSQL 7.4.6 on i386-pc-linux-gnu, compiled by GCC i386-linux-gcc (GCC)
3.3.5 (Debian 1:3.3.5-6)
PostgreSQL 8.0.1 on i386-pc-linux-gnu, compiled by GCC cc (GCC) 3.3.5
(Debian 1:3.3.5-5)

Responses

pgsql-bugs by date

Next:From: Dennis VshivkovDate: 2005-04-22 11:27:27
Subject: BUG #1618: EXTRACTing EPOCH from TIME WITH TIME ZONE is broken
Previous:From: Ron MayerDate: 2005-04-22 10:25:11
Subject: empty array can crash backend using int_array_enum from contrib.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group