| 1 | #include "duckdb/common/limits.hpp" | 
|---|---|
| 2 | #include "duckdb/parser/expression/cast_expression.hpp" | 
| 3 | #include "duckdb/parser/expression/constant_expression.hpp" | 
| 4 | #include "duckdb/parser/transformer.hpp" | 
| 5 | |
| 6 | using namespace duckdb; | 
| 7 | using namespace std; | 
| 8 | |
| 9 | unique_ptr<ParsedExpression> Transformer::TransformTypeCast(PGTypeCast *root) { | 
| 10 | if (!root) { | 
| 11 | return nullptr; | 
| 12 | } | 
| 13 | // get the type to cast to | 
| 14 | auto type_name = root->typeName; | 
| 15 | SQLType target_type = TransformTypeName(type_name); | 
| 16 | |
| 17 | //check for a constant BLOB value, then return ConstantExpression with BLOB | 
| 18 | if(target_type == SQLType::BLOB && root->arg->type == T_PGAConst) { | 
| 19 | PGAConst *c = reinterpret_cast<PGAConst *>(root->arg); | 
| 20 | if(c->val.type == T_PGString) { | 
| 21 | return make_unique<ConstantExpression>(SQLType::BLOB, Value::BLOB(string(c->val.val.str))); | 
| 22 | } | 
| 23 | } | 
| 24 | |
| 25 | // transform the expression node | 
| 26 | auto expression = TransformExpression(root->arg); | 
| 27 | |
| 28 | // now create a cast operation | 
| 29 | return make_unique<CastExpression>(target_type, move(expression)); | 
| 30 | } | 
| 31 | 
