[MDEV-15944] Subquery is not allowed as the lower FOR loop bound Created: 2018-04-20  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: Stored routines
Affects Version/s: 10.3
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-16558 Parenthesized expression does not wor... Open

 Description   

DELIMITER $$
SET @v=0;
FOR a IN (SELECT 1) .. 3 DO SET @v = @v + a; END FOR;
$$

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '.. 3 DO SET @v = @v + a; END FOR' at line 1

If I use a subquery in the upper bound, it works fine:

DELIMITER $$
SET @v=0;
FOR a IN 1 ..(SELECT 3) DO SET @v = @v + a; END FOR;
SELECT @v;
$$

+------+
| @v   |
+------+
|    6 |
+------+



 Comments   
Comment by Alexander Barkov [ 2018-06-25 ]

Note, Oracle does not support subqueries in FOR loop bounds, neither in the lower, nor in the upper:

BEGIN
  FOR a IN (SELECT 1 FROM DUAL)..2
  LOOP
    NULL;
  END LOOP;
END;
/

BEGIN
  FOR a IN 1 ..(SELECT 2 FROM DUAL)
  LOOP
    NULL;
  END LOOP;
END;
/

Generated at Thu Feb 08 08:25:11 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.