//===----------------------------------------------------------------------===// // DuckDB // // duckdb/parser/expression/cast_expression.hpp // // //===----------------------------------------------------------------------===// #pragma once #include "duckdb/parser/parsed_expression.hpp" #include "duckdb/common/types.hpp" namespace duckdb { //! CastExpression represents a type cast from one SQL type to another SQL type class CastExpression : public ParsedExpression { public: static constexpr const ExpressionClass TYPE = ExpressionClass::CAST; public: DUCKDB_API CastExpression(LogicalType target, unique_ptr child, bool try_cast = false); //! The child of the cast expression unique_ptr child; //! The type to cast to LogicalType cast_type; //! Whether or not this is a try_cast expression bool try_cast; public: string ToString() const override; static bool Equal(const CastExpression &a, const CastExpression &b); unique_ptr Copy() const override; void Serialize(FieldWriter &writer) const override; static unique_ptr Deserialize(ExpressionType type, FieldReader &source); void FormatSerialize(FormatSerializer &serializer) const override; static unique_ptr FormatDeserialize(ExpressionType type, FormatDeserializer &deserializer); public: template static string ToString(const T &entry) { return (entry.try_cast ? "TRY_CAST(" : "CAST(") + entry.child->ToString() + " AS " + entry.cast_type.ToString() + ")"; } }; } // namespace duckdb