Reactgular
Reactgular

Reputation: 54771

In this SQL example is the usage of INTERVAL correct?

I'm trying to track down a bug where the next column is not being updated with a date in the future.

Is my usage of adding INTERVAL to the next column correct?

UPDATE 
    `delay_shorts` AS `DelayShort`  
    SET 
        `DelayShort`.`delta` = 1, 
        `DelayShort`.`next` = '2002-04-14 21:31:01' + INTERVAL 5 SECOND, 
        `DelayShort`.`last_changed` = '2002-04-14 21:31:01'  
    WHERE `DelayShort`.`id` = 3

Upvotes: 1

Views: 2690

Answers (1)

Linus Kleen
Linus Kleen

Reputation: 34632

The INTERVAL expression is used in DATE_ADD or DATE_SUB functions:

UPDATE 
    `delay_shorts` AS `DelayShort`  
    SET 
        `DelayShort`.`next` = DATE_ADD('2002-04-14 21:31:01', INTERVAL 5 SECOND) 
    WHERE `DelayShort`.`id` = 3

It's important to note that the units of INTERVAL are always expressed in singular form: although you're adding 5 seconds, you express it as 5 SECOND.

Upvotes: 5

Related Questions