1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/parser/expression/subquery_expression.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/common/enums/subquery_type.hpp"
12#include "duckdb/parser/parsed_expression.hpp"
13#include "duckdb/parser/statement/select_statement.hpp"
14
15namespace duckdb {
16
17//! Represents a subquery
18class SubqueryExpression : public ParsedExpression {
19public:
20 static constexpr const ExpressionClass TYPE = ExpressionClass::SUBQUERY;
21
22public:
23 SubqueryExpression();
24
25 //! The actual subquery
26 unique_ptr<SelectStatement> subquery;
27 //! The subquery type
28 SubqueryType subquery_type;
29 //! the child expression to compare with (in case of IN, ANY, ALL operators, empty for EXISTS queries and scalar
30 //! subquery)
31 unique_ptr<ParsedExpression> child;
32 //! The comparison type of the child expression with the subquery (in case of ANY, ALL operators), empty otherwise
33 ExpressionType comparison_type;
34
35public:
36 bool HasSubquery() const override {
37 return true;
38 }
39 bool IsScalar() const override {
40 return false;
41 }
42
43 string ToString() const override;
44
45 static bool Equal(const SubqueryExpression &a, const SubqueryExpression &b);
46
47 unique_ptr<ParsedExpression> Copy() const override;
48
49 void Serialize(FieldWriter &writer) const override;
50 static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
51 void FormatSerialize(FormatSerializer &serializer) const override;
52 static unique_ptr<ParsedExpression> FormatDeserialize(ExpressionType type, FormatDeserializer &deserializer);
53};
54} // namespace duckdb
55