8000 Fix propagatesNullValues for case expr (#17796) · duckdb/duckdb@4775cca · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 4775cca

Browse files
authored
Fix propagatesNullValues for case expr (#17796)
The following query returned unexpected results: ```sql INSERT INTO integers VALUES (1), (2), (3), (NULL); SELECT i, (SELECT CASE WHEN sum(i) > 1 THEN 0 ELSE 1 END FROM integers WHERE i=i1.i) FROM integers i1; ``` ``` Expected result: ---- 1 1 2 0 3 0 NULL 1 Actual result: ---- 1 1 2 0 3 0 NULL NULL ``` This is because `PropagatesNullValues` does not strictly account for `case_expr`. A simple fix is to make it return `false` (Perhaps we can return more precise results based on the child).
2 parents 550eb85 + c60dcb0 commit 4775cca

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/planner/expression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ bool Expression::PropagatesNullValues() const {
6868
if (type == ExpressionType::OPERATOR_IS_NULL || type == ExpressionType::OPERATOR_IS_NOT_NULL ||
6969
type == ExpressionType::COMPARE_NOT_DISTINCT_FROM || type == ExpressionType::COMPARE_DISTINCT_FROM ||
7070
type == ExpressionType::CONJUNCTION_OR || type == ExpressionType::CONJUNCTION_AND ||
71-
type == ExpressionType::OPERATOR_COALESCE) {
71+
type == ExpressionType::OPERATOR_COALESCE || type == ExpressionType::CASE_EXPR) {
7272
return false;
7373
}
7474
bool propagate_null_values = true;

test/sql/subquery/scalar/test_correlated_subquery.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,10 @@ NULL NULL
192192
2 42
193193
3 42
194194

195+
query II
196+
SELECT i, (SELECT CASE WHEN sum(i) > 1 THEN 0 ELSE 1 END FROM integers WHERE i=i1.i) FROM integers i1;
197+
----
198+
1 1
199+
2 0
200+
3 0
201+
NULL 1

0 commit comments

Comments
 (0)
0