bianca_unifeye
Databricks MVP

This is expected behaviour.

  • ? parameter markers (with USING) are only for values, not for SQL identifiers.

  • When you pass a column name via ?, Databricks correctly treats it as a string literal, not as a column reference.

That’s why:

SELECT (?) FROM orders

returns a column containing the literal text o_orderpriority.

If you need to dynamically select a column name, you must build it into the SQL string:

SET sql_string =
  'SELECT ' || column_name || ' FROM orders LIMIT 10';

EXECUTE IMMEDIATE sql_string;

Rule of thumb:

  • Identifiers (tables, columns) → string concatenation

  • Values → ? + USING

This separation is intentional for correctness and SQL injection safety.

View solution in original post