MySQL UPDATE and SELECT in one pass

后端 未结 6 1349
轮回少年
轮回少年 2020-11-28 14:05

I have a MySQL table of tasks to perform, each row having parameters for a single task.
There are many worker apps (possibly on different machines), performing tasks in

6条回答
  •  遥遥无期
    2020-11-28 15:04

    UPDATE tasks
    SET guid = %d, params = @params := params
    WHERE guid = 0 LIMIT 1;
    

    It will return 1 or 0, depending on whether the values were effectively changed.

    SELECT @params AS params;
    

    This one just selects the variable from the connection.

    From: here

提交回复
热议问题