ClickHouse / ClickHouse

ClickHouse® is a real-time analytics DBMS
https://clickhouse.com
Apache License 2.0
37.53k stars 6.9k forks source link

Query params for table works but not for column name #71534

Open sanggonlee opened 2 days ago

sanggonlee commented 2 days ago

Company or project name

No response

Question

I can pass a table name to a query like so

ALTER TABLE {table: Identifier} ...

But it looks like I cannot do that with column names. Screenshot 2024-11-06 at 11 17 48 AM

Why is that so?

amabilee commented 2 days ago

ALTER TABLE {table: Identifier} would work because many SQL dialects support dynamic table names via identifiers, especially in prepared statements. However, columns are more rigid in how they're interpreted within the SQL engine.

If you need to dynamically change column names, you usually have to construct the SQL string dynamically in your application code, which then gets passed to the SQL engine.

RENAME COLUMN {old_column} TO {new_column};