Unix Technical Forum

BUG #2403: Date arithemtic using INTERVAL in UPDATE command does not work

This is a discussion on BUG #2403: Date arithemtic using INTERVAL in UPDATE command does not work within the pgsql Bugs forums, part of the PostgreSQL category; --> The following bug has been logged online: Bug reference: 2403 Logged by: Harry E. Clarke Email address: Harry.Clarke@metrosky.co.uk PostgreSQL ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 10:57 AM
Harry E. Clarke
 
Posts: n/a
Default BUG #2403: Date arithemtic using INTERVAL in UPDATE command does not work


The following bug has been logged online:

Bug reference: 2403
Logged by: Harry E. Clarke
Email address: Harry.Clarke@metrosky.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.

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 10:57 AM
Bruce Momjian
 
Posts: n/a
Default Re: BUG #2403: Date arithemtic using INTERVAL in UPDATE command

Harry E. Clarke wrote:
>
> The following bug has been logged online:
>
> Bug reference: 2403
> Logged by: Harry E. Clarke
> Email address: Harry.Clarke@metrosky.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.


That is definately a bug:

test=> SELECT INTERVAL '100' YEAR;
interval
----------
00:00:00
(1 row)

As a work-around until we fix it, please use:

test=> SELECT INTERVAL '100 year';
interval
-----------
100 years
(1 row)

with the 'YEAR' in the quotes.

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 10:57 AM
Bruno Wolff III
 
Posts: n/a
Default Re: BUG #2403: Date arithemtic using INTERVAL in UPDATE command does not work

On Sat, Apr 22, 2006 at 20:34:03 +0000,
"Harry E. Clarke" <Harry.Clarke@metrosky.co.uk> wrote:
>
> The following bug has been logged online:
>
> Bug reference: 2403
> Logged by: Harry E. Clarke
> Email address: Harry.Clarke@metrosky.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.


You probably just made a mistake with the condition. But since you haven't
shown us what it was, we can't give you any specific advice about it.

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-10-2008, 10:57 AM
Tom Lane
 
Posts: n/a
Default Re: BUG #2403: Date arithemtic using INTERVAL in UPDATE command

Bruce Momjian <pgman@candle.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.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-10-2008, 10:57 AM
Bruce Momjian
 
Posts: n/a
Default Re: BUG #2403: Date arithemtic using INTERVAL in UPDATE command

Tom Lane wrote:
> Bruce Momjian <pgman@candle.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.


I did some more research on this item, and updated the TODO item:

o Support ISO INTERVAL syntax if units cannot be determined from
the string, and are supplied after the string

The SQL standard states that the units after the string
specify the units of the string, e.g. INTERVAL '2' MINUTE
should return '00:02:00'. The current behavior has the units
restrict the interval value to the specified unit or unit
range, INTERVAL '70' SECOND returns '00:00:10'.

For syntax that isn't uniquely ISO or PG syntax, like '1' or
'1:30', treat as ISO if there is a range specification clause,
and as PG if there no clause is present, e.g. interpret '1:30'
MINUTE TO SECOND as '1 minute 30 seconds', and interpret
'1:30' as '1 hour, 30 minutes'.

This makes common cases like SELECT INTERVAL '1' MONTH
SQL-standard results. The SQL standard supports a limited
number of unit combinations and doesn't support unit names in
the string. The PostgreSQL syntax is more flexible in the
range of units supported, e.g. PostgreSQL supports '1 year 1
hour', while the SQL standard does not.

I hope this helps.

--
Bruce Momjian http://candle.pha.pa.us
EnterpriseDB http://www.enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 04-10-2008, 10:57 AM
Tom Lane
 
Posts: n/a
Default Re: BUG #2403: Date arithemtic using INTERVAL in UPDATE command

Bruce Momjian <pgman@candle.pha.pa.us> writes:
> 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:


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 ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:47 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com