Thread: date - date returns integer?

date - date returns integer?

From
Andrew Hammond
Date:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Should date - date return type integer, not interval?

/* ahammond@test:5432/test =# */ SELECT ('2005-03-04'::timestamp -
'2005-01-01'::date)::interval;
~ interval
- ----------
~ 62 days
(1 row)

/* ahammond@test:5432/test =# */ SELECT ('2005-03-04'::date -
'2005-01-01'::date)::interval;
ERROR:  cannot cast type integer to interval

- --
Andrew Hammond    416-673-4138    ahammond@ca.afilias.info
Database Administrator, Afilias Canada Corp.
CB83 2838 4B67 D40F D086 3568 81FC E7E5 27AF 4A9A
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFCKMwVgfzn5SevSpoRAlxAAJ9iPVf2yTNt11JBGc6Hun2s23+/MwCfYRwL
SzElfOrlIskOTAZucUdCeUE=
=jgOp
-----END PGP SIGNATURE-----


Re: date - date returns integer?

From
Bruno Wolff III
Date:
On Fri, Mar 04, 2005 at 15:59:02 -0500, Andrew Hammond <ahammond@ca.afilias.info> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Should date - date return type integer, not interval?

Yes. This is in the documentation.


Re: date - date returns integer?

From
Tom Lane
Date:
Andrew Hammond <ahammond@ca.afilias.info> writes:
> Should date - date return type integer, not interval?

If we made it return interval then there would be all sorts of timezone
dependencies introduced (think about DST crossings) ... which is
generally something you don't want to think about when doing date
arithmetic.  I think the definitions of these operators are fine.
        regards, tom lane