Re: Proposal for resolving casting issues - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Proposal for resolving casting issues
Date
Msg-id 5304.1032379241@sss.pgh.pa.us
Whole thread Raw
In response to Proposal for resolving casting issues  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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:06UTC' 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


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: RPMS for 7.3 beta.
Next
From: Peter Eisentraut
Date:
Subject: Re: Proposal for resolving casting issues