X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id C8C63D1B4A3 for ; Tue, 2 Mar 2004 07:01:22 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 45438-09 for ; Tue, 2 Mar 2004 03:01:03 -0400 (AST) Received: from smtp.polbox.com (smtp2.polbox.com [213.241.3.136]) by svr1.postgresql.org (Postfix) with ESMTP id CD4CDD1B83D for ; Tue, 2 Mar 2004 03:00:55 -0400 (AST) Received: (from root@localhost) by smtp.polbox.com (8.11.6/8.9.2) id i22713A22690 for pgsql-sql@postgresql.org..procmail; Tue, 2 Mar 2004 08:01:03 +0100 Received: from kitten.yoyogi.hottolink.com ([219.96.225.254]) by smtp.polbox.com (8.11.6/8.9.2) with ESMTP id i22711j22683; Tue, 2 Mar 2004 08:01:01 +0100 Date: Tue, 2 Mar 2004 16:00:46 +0900 From: Wojtek Reply-To: Wojtek X-Priority: 3 (Normal) Message-ID: <162716013640.20040302160046@polbox.com> To: Tom Lane Cc: pgsql-sql@postgresql.org Subject: Re: What's wrong with my date/interval arithmetic? In-Reply-To: <23923.1078208721@sss.pgh.pa.us> References: <16712460437.20040302150133@polbox.com> <23923.1078208721@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/21 X-Sequence-Number: 17120 TL> It is not "exactly the same arithmetic", because to_timestamp TL> delivers a result of type timestamp-with-time-zone, whereas your TL> other values are evidently timestamp without time zone. You did TL> not say what timezone setting you are using, but I think the TL> discrepancy is probably explained by that. I tried doing this: (casting to 'timestamp without timezone') select cast(to_timestamp('2003-10-17 23:07:00','YYYY-MM-dd HH24:MI:SS') as timestamp) +age(cast(to_timestamp('2003-12-01 03:50:45','YYYY-MM-dd HH24:MI:SS') as timestamp), cast(to_timestamp('2003-10-17 23:07:00','YYYY-MM-dd HH24:MI:SS') as timestamp)) And it turns out you were right Tom, the result is 2003-12-02 03:50:45, so the data type _does_ matter. Investigating that a little further I found out that there is a difference in results returned by age: select age(cast(to_timestamp('2003-12-01 03:50:45','YYYY-MM-dd HH24:MI:SS') as timestamp), cast(to_timestamp('2003-10-17 23:07:00','YYYY-MM-dd HH24:MI:SS') as timestamp)) is '1 mon 14 days 04:43:45' and select 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')) is '1 mon 13 days 04:43:45' But it still doesn't answer the questions why there is a difference in results and why it is exactly one day. The "timestamp without time zone" arithmetic should produce correct results when all operations are done _within_ that data type (without mixing types), yet I'm getting this one day discrepancy. puzzled Wojtek