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

Add parameterized RENAME queries #46407

Merged
merged 6 commits into from
Feb 18, 2023

Conversation

evillique
Copy link
Member

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Allow writing RENAME queries with query parameters. Resolves #45778

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-improvement Pull request with some product improvements label Feb 14, 2023
@tavplubix tavplubix self-assigned this Feb 14, 2023
@rschu1ze
Copy link
Member

Just as a suggestion since you are working on parameterized queries anyways right now, https://github.com/ClickHouse/product/issues/800 is similar but for CREATE USERS. Perhaps it is easy to add parameterization support for these queries as well?

Comment on lines +21 to +24
SET param_old_tbl_name = 02661_t;
SET param_new_tbl_name = 02661_t1;

CREATE TABLE {new_db_name:Identifier}.{old_tbl_name:Identifier} (a UInt64) ENGINE = MergeTree ORDER BY tuple();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should also support something like

SET param_table_name = qualified.name;

CREATE TABLE {table_name:Identifier} (a UInt64) ...

(it should create a table named name in a database named qualified)

Because qualified.name is a valid compound identifier.

Copy link
Member Author

@evillique evillique Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about how it will behave in the case when the table name contains a dot, for example `table.first` in current implementation will become default.`table.first`, and first.`table` if we change it.

Maybe we should implement special parameter type CompoundIdentifier for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to use ParserCompoundIdentifier to parse a value passed to an Identifier parameter but seems like it may be backward incompatible

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do it in a separate PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to use ParserCompoundIdentifier to parse a value passed to an Identifier parameter but seems like it may be backward incompatible

Yeah, and it seems like it will only create confusion on the user's part, so a separate type for it looks like the best solution

@evillique
Copy link
Member Author

Just as a suggestion since you are working on parameterized queries anyways right now, https://github.com/ClickHouse/product/issues/800 is similar but for CREATE USERS. Perhaps it is easy to add parameterization support for these queries as well?

Already working on it, it will be implemented as a part of this PR: #44674

@evillique evillique merged commit f93aae8 into ClickHouse:master Feb 18, 2023
@evillique evillique deleted the parameters-rename-query branch February 18, 2023 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-improvement Pull request with some product improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot rename table using {database:Identifier} parameter
4 participants