Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Referencing a procedure variable inside a non-trivial query fails #10142

@DavidLokison

Description

@DavidLokison

I am trying to set up a procedure, that (among other things) calculates an age based on the diff of a parameter and some value in the dataset.

When I manually SELECT the parameter value, it gets displayed as normal, but as soon as I JOIN another table, do it inside a subquery or use it in a function, it just "can't find the column in any table in scope".

> CREATE PROCEDURE p(IN p_birthday DATE) SELECT TIMESTAMPDIFF(YEAR, p_birthday, NOW());
> CALL p(DATE '2022-02-17');
Error 1105 (HY000): column "p_birthday" could not be found in any table in scope
> DROP PROCEDURE p;
> CREATE PROCEDURE p(IN p_birthday DATE) SELECT p_birthday AS birthday;
> CALL p(DATE '2022-02-17');
+-------------------------------+
| birthday                      |
+-------------------------------+
| 2022-02-17 00:00:00 +0000 UTC |
+-------------------------------+
> DROP PROCEDURE p;
> CREATE PROCEDURE p(IN p_birthday DATE) SELECT TIMESTAMPDIFF(YEAR, (SELECT p_birthday AS birthday), NOW());
> CALL p(DATE '2022-02-17');
Error 1105 (HY000): column "p_birthday" could not be found in any table in scope
>

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcorrectnessWe don't return the same result as MySQLcustomer issuegood reproEasily reproducible bugs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions