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

Re: Date calculation produces wrong output with 7.02

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: mark(at)summersault(dot)com, pgsql-bugs(at)postgresql(dot)org
Cc: Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>
Subject: Re: Date calculation produces wrong output with 7.02
Date: 2001-02-23 17:40:40
Message-ID: 28656.982950040@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-hackers
Mark Stosberg (mark(at)summersault(dot)com) writes:

> [PostgreSQL 7.0.2 on i686-pc-linux-gnu, compiled by gcc 2.96]
> cascade=> select date(CURRENT_DATE + ('30 days'::reltime));
>       date
> ----------
> 9097-10-20

Ugh.  What is happening here is that there is no '+' operator between
types date and reltime, but there is one between date and int4 (with
behavior of adding that many days to the date).  And reltime is
considered binary-compatible with int4, so you get

select date(CURRENT_DATE + ('30 days'::reltime)::int4);

Now '30 days'::reltime::int4 yields 2592000, so you get a silly final
result.

The correct query for Mark is

	select date(CURRENT_DATE + ('30 days'::interval));

but I wonder whether the binary equivalence between reltime and int4
might not be ill-advised.  Thomas, any thoughts here?

			regards, tom lane

In response to

pgsql-hackers by date

Next:From: Thomas LockhartDate: 2001-02-23 17:48:45
Subject: Re: Date calculation produces wrong output with 7.02
Previous:From: pgsql-bugsDate: 2001-02-23 17:18:15
Subject: Date calculation produces wrong output with 7.02

pgsql-bugs by date

Next:From: Thomas LockhartDate: 2001-02-23 17:48:45
Subject: Re: Date calculation produces wrong output with 7.02
Previous:From: pgsql-bugsDate: 2001-02-23 17:18:15
Subject: Date calculation produces wrong output with 7.02

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