我正在处理以下查询
UPDATE contacts
SET count = count + 1,
contact_id = (@contact_id := contact_id)
WHERE count = 0
ORDER BY ts_contact_scraped DESC
LIMIT 1;
SELECT *
FROM contacts
WHERE contact_id = @contact_id;
它通过以下警告,
Warning: #1287 Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'.
请告诉我需要进行哪些更改才能防止此警告?
发布于 2020-09-11 15:29:23
-- select one row for update and lock it
SELECT contact_id, ts_contact_scraped
INTO @contact_id, @ts_contact_scraped
FROM contacts
WHERE count = 0
ORDER BY ts_contact_scraped DESC
FOR UPDATE;
-- update locked row
UPDATE contacts
SET count = count + 1
WHERE contact_id = @contact_id
AND ts_contact_scraped = @ts_contact_scraped;
-- get new state of updated row
SELECT *
FROM contacts
WHERE contact_id = @contact_id
AND ts_contact_scraped = @ts_contact_scraped;
必须将contacts (contact_id, ts_contact_scraped)
定义为唯一。
https://stackoverflow.com/questions/63842136
复制相似问题