在我添加此INSERT
行之前,此工作正常。
INSERT INTO related_new(input_id,related_id, post_name, tag_count)
我知道我在where子句中使用了一个字符串,但是当没有添加INSERT
行时,它(貌似)是如何工作的。
FYI。将INSERT
行放入此proc时发生的错误是:
Truncated incorrect DOUBLE value: '1,10350
这个where子句是一个测试。
DELIMITER $$
DROP PROCEDURE IF EXISTS cursor_ROWPERROW $$
CREATE PROCEDURE cursor_ROWPERROW()
BEGIN
DECLARE cursor_ID INT;
DECLARE cursor_VAL CHAR(250);
DECLARE done INT DEFAULT FALSE;
DECLARE cursor_i CURSOR FOR select ID, tag_hash as VAL from wordpress.related_questions where tag_hash = '1,10350' limit 3;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cursor_i;
read_loop: LOOP
FETCH cursor_i INTO cursor_ID, cursor_VAL;
IF done THEN
LEAVE read_loop;
END IF;
INSERT INTO related_new(input_id,related_id, post_name, tag_count)
SELECT cursor_ID, wp_posts.id, wp_posts.post_name, count(distinct tt.term_taxonomy_id) as tag_count
FROM wp_posts
INNER JOIN wp_term_relationships tr ON (wp_posts.ID = tr.object_id)
INNER JOIN wp_term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id)
WHERE tt.term_id IN (cursor_VAL)
GROUP BY wp_posts.ID ORDER BY tag_count desc, wp_posts.post_date DESC
limit 3;
END LOOP;
CLOSE cursor_i;
END$$
DELIMITER ;