forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: do not allow subqueries to be cast to enums in views and UDFs
This commit is a follow-up to cockroachdb#106868 after additional reproductions of the original bug were found. For now, we disallow any CAST expressions that contain a subquery in the input and the target type is an ENUM. I've created cockroachdb#108184 to track this limitation. Fixes cockroachdb#107654 There is no release note because the release note from cockroachdb#106868 should be sufficient. Release note: None
- Loading branch information
Showing
5 changed files
with
60 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Regression tests for #105259 and #107654. Do not type-check subqueries in UDFs | ||
# outside optbuilder. Doing so can cause internal errors. | ||
subtest regression_105259 | ||
|
||
statement ok | ||
CREATE TYPE e105259 AS ENUM ('foo'); | ||
|
||
statement error pgcode 0A000 subqueries are not allowed in casts to enums within UDFs | ||
CREATE FUNCTION f() RETURNS VOID LANGUAGE SQL AS $$ | ||
SELECT (SELECT 'foo')::e105259; | ||
SELECT NULL; | ||
$$ | ||
|
||
statement error pgcode 0A000 subqueries are not allowed in casts to enums within UDFs | ||
CREATE FUNCTION f() RETURNS VOID LANGUAGE SQL AS $$ | ||
SELECT ( | ||
CASE WHEN true THEN (SELECT 'foo') ELSE NULL END | ||
)::e105259; | ||
SELECT NULL; | ||
$$ | ||
|
||
subtest end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters