Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Mar 10, 2025

Which issue does this PR close?

Rationale for this change

In #15090 @jayzhan211 and @goldmedal found that a test I had added in a previous PR is actually invalid

What changes are included in this PR?

Fix query to be valid

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Mar 10, 2025
union all
select * from (select c, NULL::int as a, a0 from t order by a0, c) t2
order by c, a, a0, b
order by c, a, a0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This query is not valid as b does not appear in the subquery select lists

Postgres agrees

postgres=# create table t(a0 int, a int, b int, c int);
CREATE TABLE
postgres=# insert into t values (1, 2, 3, 4);
INSERT 0 1
postgres=# insert into t values (5, 6, 7, 8);
INSERT 0 1
postgres=# select * from (select c, a, NULL::int as a0 from t order by a, c) t1
union all
select * from (select c, NULL::int as a, a0 from t order by a0, c) t2
order by c, a, a0, b
limit 2;
ERROR:  column "b" does not exist
LINE 4: order by c, a, a0, b
                           ^

The b needs to be in the subquery select list:

postgres=# select * from (select c, a, NULL::int as a0, b from t order by a, c) t1
union all
select * from (select c, NULL::int as a, a0, b from t order by a0, c) t2
order by c, a, a0, b
limit 2;
 c | a | a0 | b
---+---+----+---
 4 | 2 |    | 3
 4 |   |  1 | 3

@jayzhan211 jayzhan211 merged commit 6e422e0 into apache:main Mar 11, 2025
24 checks passed
@jayzhan211
Copy link
Contributor

Thanks @alamb

@alamb alamb deleted the alamb/fix_invalid_query branch March 11, 2025 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants