Re: Proposal for resolving casting issues

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>, Thomas Lockhart <lockhart(at)fourpalms(dot)org>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: Proposal for resolving casting issues
Date: 2002-09-18 20:00:41
Message-ID: 5304.1032379241@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> [Peter wrote:]
>> time -> interval: I'm not even sure this cast should exist at all.
>> Proper arithmetic would be IntervalValue = TimeValue - TIME 'midnight'.
>> At least make it non-implicit.

> I'd go along with marking it assignment-only.

I started to make this change, but have momentarily backed off after
observing that it causes a failure in the regression tests:

*** ./expected/horology-no-DST-before-1970.out Wed Sep 18 13:56:41 2002
--- ./results/horology.out Wed Sep 18 15:45:54 2002
***************
*** 277,287 ****

-- subtract time from date should not make sense; use interval instead
SELECT date '1991-02-03' - time '04:05:06' AS "Subtract Time";
! Subtract Time
! --------------------------
! Sat Feb 02 19:54:54 1991
! (1 row)
!
SELECT date '1991-02-03' - time with time zone '04:05:06 UTC' AS "Subtract Time UTC";
ERROR: Unable to identify an operator '-' for types 'date' and 'time with time zone'
You will have to retype this query using an explicit cast
--- 277,284 ----

-- subtract time from date should not make sense; use interval instead
SELECT date '1991-02-03' - time '04:05:06' AS "Subtract Time";
! ERROR: Unable to identify an operator '-' for types 'date' and 'time without time zone'
! You will have to retype this query using an explicit cast
SELECT date '1991-02-03' - time with time zone '04:05:06 UTC' AS "Subtract Time UTC";
ERROR: Unable to identify an operator '-' for types 'date' and 'time with time zone'
You will have to retype this query using an explicit cast

The regression test is evidently relying on the implicit cast from time
to interval to allow the date - interval operator to be used for this
query.

Now, given that the regression test itself observes that 'date - time'
is wrong, and should be 'date - interval', maybe this behavioral change
is a Good Thing. Or maybe it will just break applications. Comments?

I'm going to commit my pg_cast changes without this change later today,
but we can still go back and add this change if we decide it's good.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2002-09-18 20:09:20 Re: Proposal for resolving casting issues
Previous Message Bruce Momjian 2002-09-18 19:17:21 Re: RPMS for 7.3 beta.