Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error on C++ API document #5160

Open
toge opened this issue Mar 27, 2025 · 0 comments
Open

Runtime error on C++ API document #5160

toge opened this issue Mar 27, 2025 · 0 comments
Labels
C++ [component] C++ API

Comments

@toge
Copy link

toge commented Mar 27, 2025

I met a runtime error on C++ UDF example.

#include<duckdb.hpp>

int32_t udf_date(int32_t a) {
    return a;
}

int main() {
  con.Query("CREATE TABLE dates (d DATE)");
  con.Query("INSERT INTO dates VALUES ('1992-01-01')");
  con.CreateScalarFunction<int32_t, int32_t>("udf_date", {LogicalType::DATE}, LogicalType::DATE, &udf_date);
  con.Query("SELECT udf_date(d) FROM dates")->Print();
}

Error is following.

terminate called after throwing an instance of 'std::runtime_error'
  what():  Return type doesn't match with the first template type.

Following code works fine on my environment(Fedora Linux, gcc 14.2.1).

#include<duckdb.hpp>

int32_t udf_date(duckdb::date_t a) {
  return a.days;
}

int main() {
  con.Query("CREATE TABLE dates (d DATE)");
  con.Query("INSERT INTO dates VALUES ('1992-01-01')");
  con.CreateScalarFunction<int32_t, duckdb::date_t>("udf_date", {duckdb::LogicalType::DATE}, duckdb::LogicalType::INTEGER, udf_date);
  con.Query("SELECT udf_date(d) FROM dates")->Print();
}

Are there something wrong on my code?
Or should the document be fixed?

@szarnyasg szarnyasg added the C++ [component] C++ API label Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ [component] C++ API
Projects
None yet
Development

No branches or pull requests

2 participants