SQL general: Changes to error messages for subqueries (Preview)¶
Attention
This behavior change is in the 2026_01 bundle.
For the current status of the bundle, refer to Bundle history.
Error messages for subqueries behave in the following manner:
- Before the change:
When a subquery returns an error, the error message contains no specific information about the SQL code or object.
- After the change:
When some subqueries return an error, the error message contains specific information, such as the following details:
The line and position of the unsupported code in the subquery.
The name of the object, such as a view or function, that contains the unsupported subquery. When objects are nested, the name of the outermost object is returned. For example, if a view with an unsupported subquery is nested in a secure view, the error message shows the name of the secure view.
The name of the type of object, such as a masking policy, that contains the unsupported subquery.
There are no changes to the error codes related to subqueries.
Note
This behavior change doesn’t apply to subqueries in lateral joins or user-defined table functions (UDTFs).
Examples¶
The following examples show changes to the error messages for subqueries.
Create three tables and insert data into each of them:
CREATE TABLE testsub1(a INT, b INT)
AS SELECT * FROM VALUES
(1, 1),
(2, 2),
(NULL, NULL);
CREATE TABLE testsub2(x INT, y INT)
AS SELECT * FROM VALUES
(1, 1),
(2, 2),
(NULL, NULL);
CREATE TABLE testsub3(u INT, v INT)
AS SELECT * FROM VALUES
(1, 1),
(2, 2),
(NULL, NULL);
These tables are used in the following examples:
Unsupported subquery¶
Run an unsupported subquery that returns an error:
SELECT *
FROM testsub1
WHERE a IN(
SELECT x FROM testsub2 LEFT JOIN testsub3 ON x+a = u
);
This query returns an error because the correlated column a is in the ON clause of a left join.
Before the behavior change, the following error is returned:
002031 (42601): SQL compilation error:
Unsupported subquery type cannot be evaluated
After the behavior change, the following error is returned:
002031 (42601): SQL compilation error:
Unsupported subquery type cannot be evaluated at line 4, position 4
Secure view with an unsupported subquery¶
Create a secure view with an unsupported subquery, and query the view:
CREATE SECURE VIEW svw
AS SELECT *
FROM testsub1
WHERE a IN (
SELECT x FROM testsub2 LEFT JOIN testsub3 ON x+a = u);
SELECT * FROM svw;
Before the behavior change, the following error is returned:
002031 (42601): SQL compilation error:
Unsupported subquery type cannot be evaluated
After the behavior change, the following error is returned:
002031 (42601): SQL compilation error:
Unsupported subquery type cannot be evaluated inside VIEW object: SVW
Masking policy with an unsupported subquery¶
Create a masking policy with an unsupported subquery, alter a table to use the masking policy, and query the table:
CREATE MASKING POLICY mp AS
(i INT) RETURNS INT -> IFF(i < (SELECT MAX(a) FROM svw), i, -1);
CREATE TABLE masked_testsub1(a INT, b INT)
AS SELECT * FROM VALUES
(1, 1),
(2, 2),
(NULL, NULL);
ALTER TABLE masked_testsub1
ALTER COLUMN a SET MASKING POLICY mp;
SELECT * FROM masked_testsub1;
Before the behavior change, the following error is returned:
002031 (42601): SQL compilation error:
Unsupported subquery type cannot be evaluated
After the behavior change, the following error is returned:
002031 (42601): SQL compilation error:
Unsupported subquery type cannot be evaluated inside MASKING POLICY
Ref: 2140