#25758·duckdb

Positional column references can silently reorder macro arguments

Author: SvetufCreated Sep 15, 2026Updated Sep 17, 2026
Labelsreproduced

What happens?

Passing positional column references (#1, #2) to a macro can bind them by the input column names instead of their argument positions. If those names match the macro parameters in a different order, the query silently returns the wrong result. If the names do not match, the call can fail with a Binder Error. This appears to be the same underlying problem as #19516.

To Reproduce

sql
CREATE MACRO m(x, y) AS x - y;

SELECT m(y, x) AS by_column_name,
       m(#1, #2) AS by_column_position,
       m(#1 + 0, #2 + 0) AS with_arithmetic
FROM (VALUES (10, 3)) AS t(y, x);

Actual result:

by_column_name  by_column_position  with_arithmetic
7               -7                  7

OS:

Ubuntu 22.04.5 LTS, x86_64

DuckDB Version:

38c5eebcb0

DuckDB Client:

CLI

Hardware:

No response

Full Name:

Ilya Mishurov

Affiliation:

Postgres Professional

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?

Yes