mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Fix
This commit is contained in:
parent
a7cf7b4d6f
commit
a1aab3a82d
@ -306,6 +306,18 @@ String transformQueryForExternalDatabase(
|
||||
throw Exception("Query contains non-compatible expressions (and external_table_strict_query=true)", ErrorCodes::INCORRECT_QUERY);
|
||||
}
|
||||
|
||||
auto * literal_expr = typeid_cast<ASTLiteral *>(original_where.get());
|
||||
UInt64 value;
|
||||
if (literal_expr && literal_expr->value.tryGet<UInt64>(value) && (value == 0 || value == 1))
|
||||
{
|
||||
/// WHERE 1 -> WHERE 1=1, WHERE 0 -> WHERE 1=0.
|
||||
if (value)
|
||||
original_where = makeASTFunction("equals", std::make_shared<ASTLiteral>(1), std::make_shared<ASTLiteral>(1));
|
||||
else
|
||||
original_where = makeASTFunction("equals", std::make_shared<ASTLiteral>(1), std::make_shared<ASTLiteral>(0));
|
||||
select->setExpression(ASTSelectQuery::Expression::WHERE, std::move(original_where));
|
||||
}
|
||||
|
||||
ASTPtr select_ptr = select;
|
||||
dropAliases(select_ptr);
|
||||
|
||||
|
@ -424,6 +424,21 @@ def test_predefined_connection_configuration(started_cluster):
|
||||
cursor.execute(f'DROP TABLE test_table ')
|
||||
|
||||
|
||||
def test_where_false(started_cluster):
|
||||
cursor = started_cluster.postgres_conn.cursor()
|
||||
cursor.execute("DROP TABLE IF EXISTS test")
|
||||
cursor.execute('CREATE TABLE test (a Integer)')
|
||||
cursor.execute("INSERT INTO test SELECT 1")
|
||||
|
||||
result = node1.query("SELECT count() FROM postgresql('postgres1:5432', 'postgres', 'test', 'postgres', 'mysecretpassword') WHERE 1=0")
|
||||
assert(int(result) == 0)
|
||||
result = node1.query("SELECT count() FROM postgresql('postgres1:5432', 'postgres', 'test', 'postgres', 'mysecretpassword') WHERE 0")
|
||||
assert(int(result) == 0)
|
||||
result = node1.query("SELECT count() FROM postgresql('postgres1:5432', 'postgres', 'test', 'postgres', 'mysecretpassword') WHERE 1=1")
|
||||
assert(int(result) == 1)
|
||||
cursor.execute("DROP TABLE test")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cluster.start()
|
||||
input("Cluster created, press any key to destroy...")
|
||||
|
Loading…
Reference in New Issue
Block a user