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

Allow parametized views to be dynamic with optional parameters #49661

Open
gingerwizard opened this issue May 8, 2023 · 1 comment
Open

Allow parametized views to be dynamic with optional parameters #49661

gingerwizard opened this issue May 8, 2023 · 1 comment
Assignees
Labels

Comments

@gingerwizard
Copy link
Contributor

Currently we have to construct views with static parameters if we want to reuse them across many filters e.g.

CREATE VIEW sold_by_duration AS
SELECT
   duration,
   count() AS value
FROM default.uk_price_paid
WHERE ((postcode1 = {_postcode:String}) OR (district = {_district:String}) OR (town = {_town:String}))
GROUP BY duration


SELECT *
FROM sold_by_duration(_postcode = 'SL4', _district = 'X', _town = 'X')

Proposal is to allow a column name to be passed e.g.

CREATE VIEW sold_by_duration AS
SELECT
   duration,
   count() AS value
FROM default.uk_price_paid
WHERE _column:Column = {_value:String} 
GROUP BY duration

SELECT *
FROM sold_by_duration(_column = 'postcode1', _value = 'SL4')

Alternative and maybe complementary is to allow parameters to be optional - they will in turn be optimized away. This is more challenging obviously i.e.


SELECT *
FROM sold_by_duration(_postcode = 'SL4')

becomes

SELECT
   duration,
   count() AS value
FROM default.uk_price_paid
WHERE postcode1 = 'SL4'
GROUP BY duration

@SmitaRKulkarni SmitaRKulkarni self-assigned this May 8, 2023
@gingerwizard gingerwizard changed the title Allow parametized views to be dynamic with optional parameteras Allow parametized views to be dynamic with optional parameters May 15, 2023
@igoichuk
Copy link

igoichuk commented May 3, 2024

Would this help? https://clickhouse.com/docs/en/sql-reference/syntax#defining-and-using-query-parameters
It works to make columns parameters.

If the query parameter represents the name of a database, table, function or other identifier, use Identifier for its type. For example, the following query returns rows from a table named uk_price_paid:

SET param_mytablename = "uk_price_paid";
SELECT * FROM {mytablename:Identifier};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants