This is probably why the ANSI SQL standard specifies that
the way to get an INTERVAL from two timestamps is to subtract
them within parentheses follow that with interval_qualifier. Under
the standard you are required to SAY whether you want the
interval in days or hours, etc.
*interval_value_expression
: interval_term
Quote:
interval_value_expression_1 PLUS_SIGN interval_term_1
interval_value_expression_1 MINUS_SIGN interval_term_1
LEFT_PAREN datetime_value_expression MINUS_SIGN datetime_term
RIGHT_PAREN interval_qualifier
|
;
*interval_qualifier
: start_field TK_to end_field
*single_datetime_field
: non_second_datetime_field [ LEFT_PAREN
interval_leading_field_precision RIGHT_PAREN ]
Quote:
TK_second [ LEFT_PAREN interval_leading_field_precision [ COMMA
interval_fractional_seconds_precision ] RIGHT_PAREN ]
|
;
*non_second_datetime_field
: TK_year
Quote:
TK_month
TK_day
TK_hour
TK_minute
;
|
*interval_leading_field_precision
: UNSIGNED_INTEGER
;
*interval_fractional_seconds_precision
: UNSIGNED_INTEGER
;
Quote:
Bruce Momjian <pgman (AT) candle (DOT) pha.pa.us |
When you do a subtraction, it isn't clear if you are
interested in "days" or "hours"
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match