You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error when using a macro within if() (with Python client) #727
When using a macro within an if() statement (with the Python client), the following error is raised:
BinderException: Binder Error: Macro "if"() does not support the supplied arguments. You might need to add explicit type casts.
Candidate macros:
"if"(a, b, c)
I've tested with duckdb CLI client and I don't get this error.
To Reproduce
importduckdbduckdb.sql(
""" create macro test() as 'a'; select a: 1, if(a is null, 'a', test()), """
)
Note that if you replace the condition by a constant, e.g. true or 1=1, there's no error.
OS:
Windows
DuckDB Version:
2.0.0
DuckDB Client:
Python
Hardware:
No response
Full Name:
Maxime Nguyen
Affiliation:
CMAM
Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?
Yes, I have
Did you include all code required to reproduce the issue?
Yes, I have
Did you include all relevant data sets for reproducing the issue?
I tried this on DuckDB 2.0.0 and on our current 2.0.1 and 2.1 dev builds. It returns (1, 'a') every time. I also tried con.sql(), con.execute(), a prepared statement, Windows line endings, and the relation methods (printing it, .df(), .arrow(), .pl()). None of them raise the error. My runs were on Linux, not Windows, though the binder code involved does not depend on the platform.
The error means the if macro saw arguments it could not match. That usually happens when one of the arguments carries a name, or when the number of arguments is not three. So I suspect something in your session or your real query differs from the snippet.
Can you try to:
Run the snippet as a script in a fresh Python process, not in an open notebook or REPL, and tell me whether it still fails.
Paste the output of import duckdb; print(duckdb.version) from that same environment.
Paste the full traceback.
Are you connecting to a database file or using any extensions? If so, which ones?
Until then, case when a is null then 'a' else test() end is a workaround.
Indeed, I should have tried in a new environment without any settings/extensions. Thanks to your advices, I managed to find where the issue is coming from.
I'm using the community extension mssql to attach my SQL Server database, and it seems that it causes the if macro to not work properly.
I'll forward the issue to them, thanks again!
EDIT: After raising the issue on the extension repo, it appears that it's actually coming from core duckdb 2.0, but it should be fixed in 2.0.1.
Activity
evertlammerts commentedon Oct 29, 2026
Thanks for the report and the repro, @Hunknown.
I tried this on DuckDB 2.0.0 and on our current 2.0.1 and 2.1 dev builds. It returns
(1, 'a')every time. I also triedcon.sql(),con.execute(), a prepared statement, Windows line endings, and the relation methods (printing it,.df(),.arrow(),.pl()). None of them raise the error. My runs were on Linux, not Windows, though the binder code involved does not depend on the platform.The error means the if macro saw arguments it could not match. That usually happens when one of the arguments carries a name, or when the number of arguments is not three. So I suspect something in your session or your real query differs from the snippet.
Can you try to:
Until then,
case when a is null then 'a' else test() endis a workaround.Hunknown commentedon Oct 30, 2026
@evertlammerts Thank you for the investigation!
Indeed, I should have tried in a new environment without any settings/extensions. Thanks to your advices, I managed to find where the issue is coming from.
I'm using the community extension mssql to attach my SQL Server database, and it seems that it causes the
ifmacro to not work properly.I'll forward the issue to them, thanks again!
EDIT: After raising the issue on the extension repo, it appears that it's actually coming from core duckdb 2.0, but it should be fixed in 2.0.1.