Thread: Huh? Data typing bug?

Huh? Data typing bug?

From
"Josh Berkus"
Date:
Folks,
I just subtracted two dates and got an INT4, rather than the INTERVAL I
was expecting.  What goes on here?

-Josh


______AGLIO DATABASE SOLUTIONS___________________________                                      Josh Berkus Complete
informationtechnology      josh@agliodbs.com  and data management solutions       (415) 565-7293 for law firms, small
businesses       fax 621-2533   and non-profit organizations.      San Francisco
 


Re: Huh? Data typing bug?

From
Grant
Date:
You got difference in seconds as the result?

Show some examples.



Re: Huh? Data typing bug?

From
Tom Lane
Date:
"Josh Berkus" <josh@agliodbs.com> writes:
>     I just subtracted two dates and got an INT4, rather than the INTERVAL I
> was expecting.  What goes on here?

IIRC, number of days (as an int) is what that's supposed to produce.

If that's not what you wanted, maybe you ought to cast the dates to
timestamp or some such.
        regards, tom lane


Re: Huh? Data typing bug?

From
"Josh Berkus"
Date:
Tom,

> IIRC, number of days (as an int) is what that's supposed to produce.
> 
> If that's not what you wanted, maybe you ought to cast the dates to
> timestamp or some such.

I see.  It was never made clear to me that here the DATE type differs
from DATETIME and TIMESTAMP significantly.  

This makes some sort of sense, now.

Correct me if I'm wrong:

DATE + INT4 = DATE
DATE - DATE = INT4

But:

DATETIME + INTERVAL = DATETIME
DATETIME - DATETIME = INTERVAL

-Josh


______AGLIO DATABASE SOLUTIONS___________________________                                      Josh Berkus Complete
informationtechnology      josh@agliodbs.com  and data management solutions       (415) 565-7293 for law firms, small
businesses       fax 621-2533   and non-profit organizations.      San Francisco