Interpret subquery with empty result as Null literal. [#CLICKHOUSE-2760]

This commit is contained in:
Vitaliy Lyudvichenko 2017-02-02 03:55:14 +03:00 committed by alexey-milovidov
parent 67d8ce3568
commit 11b3aad985
3 changed files with 15 additions and 1 deletions

View File

@ -989,7 +989,11 @@ void ExpressionAnalyzer::executeScalarSubqueriesImpl(ASTPtr & ast)
block = res.in->read();
if (!block)
throw Exception("Scalar subquery returned empty result", ErrorCodes::INCORRECT_RESULT_OF_SCALAR_SUBQUERY);
{
/// Interpret subquery with empty result as Null literal
ast = std::make_unique<ASTLiteral>(ast->range, Null());
return;
}
if (block.rows() != 1 || res.in->read())
throw Exception("Scalar subquery returned more than one row", ErrorCodes::INCORRECT_RESULT_OF_SCALAR_SUBQUERY);

View File

@ -0,0 +1,5 @@
\N
\N
\N
\N
\N

View File

@ -0,0 +1,5 @@
SELECT (SELECT 1 WHERE 0);
SELECT (SELECT * FROM (SELECT * FROM system.numbers LIMIT 2) WHERE number = number + 1);
SELECT (SELECT Null WHERE 1);
SELECT (SELECT NULL WHERE 0);
SELECT (SELECT Null WHERE nuLL IS NOT NULL);