![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
select '2005-08-31'::date + '1 month'::interval-'1 month'::interval from the mathematical me the resulting value should be '2005-08-31' |
#3
| |||
| |||
|
|
Apparently the two intervals don't cancel each other out (i.e., they're not optimized to zero), |
|
so effectively we get this: test=> select '2005-08-31'::date + '1 month'::interval; ?column? --------------------- 2005-09-30 00:00:00 (1 row) |
#4
| |||
| |||
|
|
Michael Fuhr <mike (AT) fuhr (DOT) org> writes: Apparently the two intervals don't cancel each other out (i.e., they're not optimized to zero), Well, no, because + and - associate left-to-right. |
|
test=> select '2005-08-31'::date + '1 month'::interval; ?column? --------------------- 2005-09-30 00:00:00 (1 row) This seems to be the crux of the issue: is the above expression valid and if so what should it yield? |
|
date_add('2005-08-31', interval 1 month) | +------------------------------------------+ 2005-09-30 | +------------------------------------------+ |
#5
| |||
| |||
|
|
[ Mike's unhappy that ] these give different answers: select '2005-08-30'::date + '1 day'::interval + '1 month'::interval, '2005-08-30'::date + '1 month'::interval + '1 day'::interval; |
|
Wait a minute, here's proof that it *must* be wrong ;-) mysql> select date_add('2005-08-31', interval 1 month); | 2005-09-30 | |
|
What do other DBMSs do? |
#6
| |||
| |||
|
|
Michael Fuhr <mike (AT) fuhr (DOT) org> writes: What do other DBMSs do? This is a fair question. Given that the SQL committee hasn't provided any useful leadership, what are other groups doing? |
#7
| |||
| |||
|
|
I just noticed something in PostgreSQL that might be considered surprising (although I do see "Add ISO INTERVAL handling" in the TODO list): test=> select interval '1' month; interval ---------- 00:00:00 (1 row) What's the parser doing here? |
#8
| |||
| |||
|
|
Michael Fuhr <mike (AT) fuhr (DOT) org> writes: I just noticed something in PostgreSQL that might be considered surprising (although I do see "Add ISO INTERVAL handling" in the TODO list): test=> select interval '1' month; interval ---------- 00:00:00 (1 row) What's the parser doing here? Not getting it right ;-). Trying this in historical versions is amusing: 7.0: regression=# select interval '1' month; ERROR: parser: parse error at or near "month" 7.1: regression=# select interval '1' month; ERROR: Bad interval external representation '1' 7.2: regression=# select interval '1' month; interval ---------- 00:00 (1 row) 7.3: regression=# select interval '1' month; interval ---------- 00:00:01 (1 row) 7.4 and up: regression=# select interval '1' month; interval ---------- 00:00:00 (1 row) What is happening in the current versions is that coerce_type thinks it can coerce the literal string to interval without supplying the modifier, and then use interval_scale() to apply the typmod. This works OK for most of the data types, but not for interval it seems... Basically the support for these weird syntaxes is something that Tom Lockhart never finished, and no one has bothered to pick up the work since he left the project. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq |
![]() |
| Thread Tools | |
| Display Modes | |
| |