Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
5.5(EOL), 10.0(EOL), 10.1(EOL), 10.2(EOL), 10.3(EOL), 10.4(EOL)
-
None
Description
DELIMITER $$
|
CREATE OR REPLACE PROCEDURE p1(a INT) |
BEGIN
|
DECLARE res INT DEFAULT 0; |
IF (a < 0) THEN |
SET res=x; |
END IF; |
END; |
$$
|
DELIMITER ;
|
Now if I call the procedure as follows:
CALL p1(0);
|
it still returns no errors.
It only returns an error if the condition in IF evaluates to true:
call p1(-1);
|
ERROR 1054 (42S22): Unknown column 'x' in 'field list'
|
This behavior makes it very difficult to design stored procedures.
The error should happen during CREATE PROCEDURE time.
In this context, x can only be a variable. It cannot be a column because no tables are involved.
Attachments
Issue Links
- relates to
-
MDEV-11953 support of brackets (parentheses) in UNION/EXCEPT/INTERSECT operations
-
- Closed
-
-
MDEV-22774 Invalid use of aggregate function in SP is not detected at CREATE time
-
- Open
-
Activity
Field | Original Value | New Value |
---|---|---|
Rank | Ranked higher |
Description |
{code:sql}
DELIMITER $$ CREATE OR REPLACE PROCEDURE p1(a INT) BEGIN DECLARE res INT DEFAULT 0; IF (a < 0) THEN SET res=x; END IF; END; $$ DELIMITER ; {code} Now if I call the procedure as follows: {code:sql} CALL p1(0); {code} it still returns no errors. It only returns an error if the condition in {{IF}} evaluates to {{true}}: {code:sql call p(-1); {code} {noformat} ERROR 1054 (42S22): Unknown column 'x' in 'field list' {noformat} This behavior makes it very difficult to design stored procedures. The error should happen during {{CREATE PROCEDURE}} time. In this context, {{x}} can only be a variable. It cannot be a column because no tables are involved. |
{code:sql}
DELIMITER $$ CREATE OR REPLACE PROCEDURE p1(a INT) BEGIN DECLARE res INT DEFAULT 0; IF (a < 0) THEN SET res=x; END IF; END; $$ DELIMITER ; {code} Now if I call the procedure as follows: {code:sql} CALL p1(0); {code} it still returns no errors. It only returns an error if the condition in {{IF}} evaluates to {{true}}: {code:sql} call p(-1); {code} {noformat} ERROR 1054 (42S22): Unknown column 'x' in 'field list' {noformat} This behavior makes it very difficult to design stored procedures. The error should happen during {{CREATE PROCEDURE}} time. In this context, {{x}} can only be a variable. It cannot be a column because no tables are involved. |
Link |
This issue relates to |
Status | Open [ 1 ] | In Progress [ 3 ] |
Fix Version/s | 10.4 [ 22408 ] | |
Fix Version/s | 10.3 [ 22126 ] |
Description |
{code:sql}
DELIMITER $$ CREATE OR REPLACE PROCEDURE p1(a INT) BEGIN DECLARE res INT DEFAULT 0; IF (a < 0) THEN SET res=x; END IF; END; $$ DELIMITER ; {code} Now if I call the procedure as follows: {code:sql} CALL p1(0); {code} it still returns no errors. It only returns an error if the condition in {{IF}} evaluates to {{true}}: {code:sql} call p(-1); {code} {noformat} ERROR 1054 (42S22): Unknown column 'x' in 'field list' {noformat} This behavior makes it very difficult to design stored procedures. The error should happen during {{CREATE PROCEDURE}} time. In this context, {{x}} can only be a variable. It cannot be a column because no tables are involved. |
{code:sql}
DELIMITER $$ CREATE OR REPLACE PROCEDURE p1(a INT) BEGIN DECLARE res INT DEFAULT 0; IF (a < 0) THEN SET res=x; END IF; END; $$ DELIMITER ; {code} Now if I call the procedure as follows: {code:sql} CALL p1(0); {code} it still returns no errors. It only returns an error if the condition in {{IF}} evaluates to {{true}}: {code:sql} call p1(-1); {code} {noformat} ERROR 1054 (42S22): Unknown column 'x' in 'field list' {noformat} This behavior makes it very difficult to design stored procedures. The error should happen during {{CREATE PROCEDURE}} time. In this context, {{x}} can only be a variable. It cannot be a column because no tables are involved. |
Fix Version/s | 10.5 [ 23123 ] | |
Fix Version/s | 10.4 [ 22408 ] |
Affects Version/s | 10.4 [ 22408 ] |
Status | In Progress [ 3 ] | Stalled [ 10000 ] |
Link | This issue relates to MDEV-22774 [ MDEV-22774 ] |
Comment |
[ The same problem is repeatable with aggregate functions:
{code:sql} CREATE OR REPLACE FUNCTION f1() RETURNS INT RETURN SUM(1); SELECT f1(); {code} {noformat} ERROR 1111 (HY000): Invalid use of group function {noformat} And window functions: {code:sql} CREATE OR REPLACE FUNCTION f1() RETURNS INT RETURN ROW_NUMBER() OVER(); SELECT f1(); {code} {noformat} ERROR 4015 (HY000): Window function is allowed only in SELECT list and ORDER BY clause {noformat} It should report the error at creation rather than execution time. ] |
Assignee | Alexander Barkov [ bar ] | Oleksandr Byelkin [ sanja ] |
Assignee | Oleksandr Byelkin [ sanja ] | Alexander Barkov [ bar ] |
Status | Stalled [ 10000 ] | In Progress [ 3 ] |
Assignee | Alexander Barkov [ bar ] | Oleksandr Byelkin [ sanja ] |
Status | In Progress [ 3 ] | In Review [ 10002 ] |
Status | In Review [ 10002 ] | Stalled [ 10000 ] |
Assignee | Oleksandr Byelkin [ sanja ] | Alexander Barkov [ bar ] |
issue.field.resolutiondate | 2020-06-10 14:39:30.0 | 2020-06-10 14:39:30.07 |
Fix Version/s | 10.5.4 [ 24264 ] | |
Fix Version/s | 10.5 [ 23123 ] | |
Resolution | Fixed [ 1 ] | |
Status | Stalled [ 10000 ] | Closed [ 6 ] |
Workflow | MariaDB v3 [ 83736 ] | MariaDB v4 [ 153158 ] |
More examples when an error is not returned:
DELIMITER $$
BEGIN
$$
DELIMITER ;
DELIMITER $$
BEGIN
$$
DELIMITER ;
DELIMITER $$
BEGIN
$$
DELIMITER ;
DELIMITER $$
BEGIN
$$
DELIMITER ;