-
Notifications
You must be signed in to change notification settings - Fork 229
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
select
clause after append
clause
#2680
Comments
Yup, that's a bug. When the compiler encounters c1, c2 and c3 it infers that they are from tb1, while is should find both tb1 and tb2. |
I would expect SQL to be: WITH table_1 AS (
SELECT
c1, c2, c3
FROM
tb1
UNION
ALL
SELECT
c1, c2, c3
FROM
tb2
)
SELECT
c1 * 2 AS new_col1,
c2 / c3 AS new_col2
FROM
table_1 AS table_0 |
Rewriting the original input to the new syntax:
Still produces the wrong output as of 0.13.3: WITH table_0 AS (
SELECT
c2,
c3,
c1
FROM
tb1
UNION
ALL
SELECT
*
FROM
tb2
)
SELECT
c1 * 2 AS new_col1,
c2 / c3 AS new_col2
FROM
table_0
-- Generated by PRQL compiler version:0.13.3-39-ge393ab4d (https://prql-lang.org) Importantly, an attempted workaround to explicitly select columns from
WITH table_0 AS (
SELECT
c1,
c2,
c3
FROM
tb2
),
table_1 AS (
SELECT
c2,
c3,
c1
FROM
tb1
UNION
ALL
SELECT
*
FROM
table_0
)
SELECT
c1 * 2 AS new_col1,
c2 / c3 AS new_col2
FROM
table_1
-- Generated by PRQL compiler version:0.13.3-39-ge393ab4d (https://prql-lang.org) While the number of columns from |
What happened?
Dear developer,
Hope this would be helpful.
prql version: 0.8.1
comments: The
select
clause affects the translation ofappend
clause. It might be caused by internal optimization in prql compiler.In the following example, we assume
tb1
andtb2
have the same columns. We appendtb2
totb1
, and select two new columns. However, inside generated sql query, it selects new columns first. Then theunion
operation fails.error message from the database: "each UNION query must have the same number of columns"
PRQL input
SQL output
Expected SQL output
MVCE confirmation
Anything else?
No response
The text was updated successfully, but these errors were encountered: