DATE casting and INTERVAL addition or subtraction confusion.

Database
Enthusiast

DATE casting and INTERVAL addition or subtraction confusion.

The following works fine:

SEL CAST((DATE '2005-03-01' - DATE '2005-01-01') AS INTERVAL DAY) + INTERVAL '3' DAY;
*** Query completed. One row found. One column returned.

((2005-03-01-2005-01-01)+ 3)
----------------------------
62

The following also works:

SEL (DATE '2005-03-01' - DATE '2005-01-01') DAY;
*** Query completed. One row found. One column returned.

(2005-03-01 - 2005-01-01) DAY
-----------------------------
59

The notes I'm looking at say for #2: "This result is an INTERVAL DAY (2) data type. It may be used in INTERVAL calculations. "

However the next statement does not:

SEL (DATE '2005-03-01' - DATE '2005-01-01') DAY + INTERVAL '3' DAY;
*** Failure 3706 Syntax error: expected something between the 'DAY' keyword and '+'.

Ideas guys?
1 REPLY
Enthusiast

Re: DATE casting and INTERVAL addition or subtraction confusion.

Never mind - I didn't realise bracket precedence:
sel ((DATE '2005-03-01' - DATE '2005-01-01') DAY) + interval '3' day;
*** Query completed. One row found. One column returned.

((2005-03-01 - 2005-01-01) DAY+ 3)
----------------------------------
62