![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
The following bug has been logged online: Bug reference: 2403 Logged by: Harry E. Clarke Email address: Harry.Clarke (AT) metrosky (DOT) co.uk PostgreSQL version: 8.1.3 Operating system: Suse Linux 10.0 Description: Date arithemtic using INTERVAL in UPDATE command does not work Details: Entering the command UPDATE table SET col_date = col_date - INTERVAL '100' YEAR where condition; does not perform any date aritimetic, and thus the date value in col_date remains unchanged. col_date contains a value such as '2039-12-07'. If the command UPDATE table SET col_date = DATE '1939-12-07' where condition; is entered, the command executes as expected. |
#2
| |||
| |||
|
|
That is definately a bug: test=> SELECT INTERVAL '100' YEAR; |
|
As a work-around until we fix it, please use: test=> SELECT INTERVAL '100 year'; |
#3
| |||
| |||
|
|
Bruce Momjian <pgman (AT) candle (DOT) pha.pa.us> writes: That is definately a bug: test=> SELECT INTERVAL '100' YEAR; We don't currently support that style of specifying interval constants, and you shouldn't hold your breath expecting it to happen --- it will require a whole bunch of abuse of the currently data-type-independent processing of literal constants. I don't think anyone's even thought about it since Tom Lockhart stopped working on that part of the code. The fact that the syntax is accepted at all is just because he had done some preliminary work on the grammar, but there's no infrastructure behind the grammar for handling it. In short, you need to calibrate your expectations as "feature addition someday", not "bug fix". As a work-around until we fix it, please use: test=> SELECT INTERVAL '100 year'; This is the syntax we support. |
#4
| |||
| |||
|
|
Tom Lane wrote: We don't currently support that style of specifying interval constants, and you shouldn't hold your breath expecting it to happen --- it will require a whole bunch of abuse of the currently data-type-independent processing of literal constants. I did some more research on this item, and updated the TODO item: |
#5
| |||
| |||
|
|
BTW, I looked at the problem a little bit and concluded that it wouldn't be so invasive to fix as all that. The weak spot at the moment is that parse_coerce() passes typmod -1 instead of the specified typmod to the datatype's input routine when converting an unknown-type literal. It has to do that to get the right behavior for varchar(N) and char(N) ... but we could imagine hacking it to behave differently for interval. At the most grotty, if (targetTypeId == INTERVALOID) pass targetTypeMod; else pass -1; but maybe something cleaner could be devised. That would take care of getting the info to interval_in(), and then the question is what interval_in() should do with it. Your notes in the TODO entry look like they summarize previous discussion accurately. It's worth pointing out that this would also affect data input, eg COPY into an interval column would interpret '100' differently depending on how the column had been declared. I think this is OK but it'd need some consideration. Actually implementing this is left as a task for someone who feels like hacking on the datetime code ... I don't particularly ... |
#6
| |||
| |||
|
|
Tom Lane wrote: Actually implementing this is left as a task for someone who feels like hacking on the datetime code ... I don't particularly ... I think this is a perfect project for Summer of Code. |
![]() |
| Thread Tools | |
| Display Modes | |
| |