time interval behaviour seems odd

From: Tilo Schwarz <mail(at)tilo-schwarz(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: time interval behaviour seems odd
Date: 2003-12-17 19:56:38
Message-ID: 200312172056.38376.mail@tilo-schwarz.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

while trying to create a query this afternoon dealing with intervals, I
noticed the following behaviour and I wondered, if it is intended. (It was
non-intuitive to me and if there was a warning in the docs i missed it.)
The lines marked <--- make me wonder ...

tschwarz=> select version();
version
------------------------------------------------------------------------
PostgreSQL 7.3.2 on i386-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.3
(1 row)

tschwarz=> select '1'::interval;
interval
----------
00:00:01
(1 row)

tschwarz=> select -'1'::interval;
?column?
-----------
-00:00:01
(1 row)

tschwarz=> select '-1'::interval;
interval
----------
-01:00 <---
(1 row)

tschwarz=> select -'-1'::interval;
?column?
----------
01:00 <---
(1 row)

Now with 1.0 everything looks fine:

tschwarz=> select '1.0'::interval;
interval
----------
00:00:01
(1 row)

tschwarz=> select -'1.0'::interval;
?column?
-----------
-00:00:01
(1 row)

tschwarz=> select '-1.0'::interval;
interval
-----------
-00:00:01
(1 row)

tschwarz=> select -'-1.0'::interval;
?column?
----------
00:00:01
(1 row)

But look at 0.1:

tschwarz=> select '0.1'::interval;
interval
-------------
00:00:00.10
(1 row)

tschwarz=> select -'0.1'::interval;
?column?
--------------
-00:00:00.10
(1 row)

tschwarz=> select '-0.1'::interval;
interval
-------------
00:00:00.10 <---
(1 row)

tschwarz=> select -'-0.1'::interval;
?column?
--------------
-00:00:00.10 <---
(1 row)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Marko Zmak 2003-12-17 20:34:17 TODO list
Previous Message Andrew Dunstan 2003-12-17 18:49:31 Re: [PATCHES] Double Backslash example patch