0

Here is an interesting thought.

UPDATE table1
SET field1 = UNIX_TIMESTAMP()
WHERE
    field1 <= UNIX_TIMESTAMP() - 600
AND field2 > UNIX_TIMESTAMP() - 1000

Will the three time stamp may result in different values .. or if there is a chance that MySQL may intelligently evaluate these once and use the result in all three of these ?

1
  • 1
    if there is a chance that MySQL may intelligently evaluate these once and use the result in all three of these. I've tested it out of curiosity. Called UNIX_TIMESTAMP() 5030 times in a query and it took **206 ** Seconds and the results are all same. Commented Feb 9, 2016 at 15:16

2 Answers 2

1

Interestingly, this is not properly documented for UNIX_TIMESTAMP(). For NOW(), the documentation is quite clear:

NOW() returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger, NOW() returns the time at which the function or triggering statement began to execute.) This differs from the behavior for SYSDATE(), which returns the exact time at which it executes.

I think UNIX_TIMETAMP() follows the same rules as NOW(), but I'm not 100% sure.

Sign up to request clarification or add additional context in comments.

Comments

0

I think you don't want to repeat unix_timestamp().

SET @now = NOW();
UPDATE table1
SET field1 = @now
WHERE
   field1 <= @now - 600
   AND field2 > @now - 1000;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.