Skip to content

Commit f26734f

Browse files
committed
Add support for try expressions
1 parent 89ed9a1 commit f26734f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/duckdb_py/include/duckdb_python/expression/pyexpression.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ struct DuckDBPyExpression : public enable_shared_from_this<DuckDBPyExpression> {
8383
shared_ptr<DuckDBPyExpression> In(const py::args &args);
8484
shared_ptr<DuckDBPyExpression> NotIn(const py::args &args);
8585

86+
// TRY
87+
88+
shared_ptr<DuckDBPyExpression> Try()
89+
8690
// Order modifiers
8791

8892
shared_ptr<DuckDBPyExpression> Ascending();

src/duckdb_py/pyexpression.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ shared_ptr<DuckDBPyExpression> DuckDBPyExpression::NotIn(const py::args &args) {
226226
return CreateCompareExpression(ExpressionType::COMPARE_NOT_IN, args);
227227
}
228228

229+
// TRY
230+
231+
shared_ptr<DuckDBPyExpression> DuckDBPyExpression::Try() {
232+
return DuckDBPyExpression::InternalUnaryOperator(ExpressionType::OPERATOR_TRY, *this);
233+
}
234+
235+
229236
// COALESCE
230237

231238
shared_ptr<DuckDBPyExpression> DuckDBPyExpression::Coalesce(const py::args &args) {
@@ -431,6 +438,7 @@ shared_ptr<DuckDBPyExpression> DuckDBPyExpression::SQLExpression(string sql) {
431438
return make_shared_ptr<DuckDBPyExpression>(std::move(expressions[0]));
432439
}
433440

441+
434442
// Private methods
435443

436444
shared_ptr<DuckDBPyExpression> DuckDBPyExpression::BinaryOperator(const string &function_name,

src/duckdb_py/pyexpression/initialize.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,14 @@ void DuckDBPyExpression::Initialize(py::module_ &m) {
367367
)";
368368
expression.def("isnotin", &DuckDBPyExpression::NotIn, docs);
369369

370+
docs = R"(
371+
Create a TRY expression from self
372+
373+
Returns:
374+
DuckDBPyExpression: TRY(self)
375+
)";
376+
expression.def("try", &DuckDBPyExpression::Try, docs);
377+
370378
docs = R"(
371379
Return the stringified version of the expression.
372380

0 commit comments

Comments
 (0)