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

sql: Support PIVOT query syntax in SQL parser #1678

Closed
denimalpaca opened this issue Feb 28, 2023 · 3 comments
Closed

sql: Support PIVOT query syntax in SQL parser #1678

denimalpaca opened this issue Feb 28, 2023 · 3 comments
Assignees

Comments

@denimalpaca
Copy link
Contributor

denimalpaca commented Feb 28, 2023

Add SQL parser support for the remaining (complicated) cases for the CREATE OR REPLACE command in Snowflake.

CREATE OR REPLACE table metrics.combined_monthly_tmp AS (    with acct_summary AS (
        SELECT
            u.eom_date,
            u.parent_id,
        FROM metrics.usage_monthly u
    )

    , pivot_summary AS (

        SELECT
            p.*
        FROM summary a
            PIVOT (SUM(a.usage) FOR a.inv_item_type IN ('item1', 'item2', 'item3')) AS p
        (eom_date, parent_id)
    )

    SELECT
        cc.eom_date,
        parent_id,
        ROUND(NVL(u.item1, 0), 2) item1_amt,
        ROUND(NVL(u.item2, 0), 2) item2_amt,
        ROUND(NVL(u.item_3, 0), 2) item3_amt,
    FROM pivot_summary u
        FULL JOIN metrics.usage_monthly c
            USING (parent_id, eom_date)
        LEFT JOIN commons.calendar cc
            ON  cc.date = NVL(u.eom_date, c.eom_date)
    ORDER BY
        parent_id,
        c.eom_date)
@pawel-big-lebowski
Copy link
Contributor

@denimalpaca Sqlparser library already has support for create or replace (see code). Please provide some examples on what is missing.

@pawel-big-lebowski pawel-big-lebowski changed the title sql: Support more CREATE OR REPLACE Snowflake query cases sql: Support PIVOT query syntax Mar 13, 2023
@pawel-big-lebowski pawel-big-lebowski changed the title sql: Support PIVOT query syntax sql: Support PIVOT query syntax in SQL parser Mar 13, 2023
@pawel-big-lebowski
Copy link
Contributor

The issue with the example query provided is related to missing support of PIVOT query syntax (Snowflake doc) within sqlparser.

@pawel-big-lebowski
Copy link
Contributor

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

No branches or pull requests

2 participants