pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Wojtek <wojtg@polbox.com>
To: pgsql-sql@postgresql.org
Subject: What's wrong with my date/interval arithmetic?
Date: Tue, 2 Mar 2004 15:01:33 +0900
Message-ID: <16712460437.20040302150133@polbox.com> (raw)

Hi,

I ran this query on Postgres 7.3:

select min_time, max_time, min_time+age(max_time,min_time) as result,
        to_timestamp('2003-10-17 23:07:00','YYYY-MM-dd HH24:MI:SS')
        +age(to_timestamp('2003-12-01 03:50:45','YYYY-MM-dd HH24:MI:SS'),
     to_timestamp('2003-10-17 23:07:00','YYYY-MM-dd HH24:MI:SS')) as expected_result from
(select min(postingblogdate) as min_time from blg_weblog_header) as min_time,
(select max(postingblogdate) as max_time from blg_weblog_header) as max_time

and get a result like this:
min_time,max_time,result,expected_result
2003-10-17 23:07:00,2003-12-01 03:50:45,2003-12-02 03:50:45,2003-12-01 03:50:45

Why is the "result" incorrect (off by one day)?
When I do the exactly same arithmetic using timestamps created
with to_timestamp, everything is OK ("expected_result").
Is this a bug or am I doing something worng?

thanks for any thoughts about this problem,
Wojtek

P.S. postingblogdate is of type "timestamp without time zone"




view thread (4+ messages)  latest in thread

Message-ID: <16712460437.20040302150133@polbox.com>
Permalink:  ../16712460437.20040302150133@polbox.com/
Also on:    postgresql.org/message-id/16712460437.20040302150133@polbox.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: wojtg@polbox.com
  Subject: Re: What's wrong with my date/interval arithmetic?
  In-Reply-To: <16712460437.20040302150133@polbox.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox