MySQL Forums
Forum List  »  General

User defined variables inside update statement
Posted by: Dragos Matei
Date: March 15, 2017 10:13AM

Hello,

Has anyone used user-defined session variables to avoid an extra select ?
For e.g. to give away one record from a stockpile, one would run something
like:

UPDATE `promotion_codes`
SET `is_claimed` = 1,
`code` = (@promotion_code := `code`)
WHERE `promotion_type` = 3
LIMIT 1;

SELECT @promotion_code;

This way, the SELECT will be fast since it just reads the value in memory
without going to the table space.

But could there be any issues with using user-defined variables like this,
inside update statements with limit 1 ?

Best,
Dragos

Options: ReplyQuote


Subject
Written By
Posted
User defined variables inside update statement
March 15, 2017 10:13AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.