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 Support for Dynamic SQL Macros for Flexible Column Selection #14512

Open
Tracked by #14514
berkaysynnada opened this issue Feb 5, 2025 · 2 comments
Open
Tracked by #14514
Labels
enhancement New feature or request

Comments

@berkaysynnada
Copy link
Contributor

Is your feature request related to a problem or challenge?

People may need to write flexible SQL queries that adapt to different table schemas without hardcoding column names.

Query reusability is very limited currently, and creating dynamic queries requires external templating. A built-in mechanism to define and use dynamic SQL macros would significantly enhance the expressiveness and reusability

Describe the solution you'd like

Introduce support for dynamic SQL macros that allow users to parameterize column selection. For example, a macro could accept lists of columns to include or exclude and then automatically select the appropriate columns from a given table or CTE. An example usage might look like this:

CREATE OR REPLACE MACRO dynamic_select(
    include_cols, 
    exclude_cols 
) AS TABLE (
    FROM source_table
    SELECT
        COLUMNS(col -> 
            (list_contains(include_cols, col))
            AND
            (NOT list_contains(exclude_cols, col))
        )
);

WITH source_table AS (
    SELECT * FROM employees
)
FROM dynamic_select(
    ['id', 'name', 'department'], 
    ['salary']                 
);

Describe alternatives you've considered

No response

Additional context

No response

@khushishukla2813
Copy link

khushishukla2813 commented Mar 6, 2025

Hey @berkaysynnada Im interested in this issue and wanna participate in GSoC. Before making changes I want to understand where to store macro definitions in memory, catalog, or elsewhere nd should I modify parser.rs to support CREATE MACRO nd also how macros gonna integrate into query execution,,,

@berkaysynnada
Copy link
Contributor Author

where to store macro definitions in memory, catalog, or elsewhere
how macros gonna integrate into query execution

These questions are not easy to answer straightforwardly at the moment. Once the project assignments are done, we will focus on these questions during the first week and likely discuss them with the entire community. However, if you develop some intuition and can make proposals, it will certainly be beneficial.

should I modify parser.rs to support CREATE MACRO

Yeah, you probably should

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

No branches or pull requests

2 participants