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

feat: SELECT * EXCEPT [columnA,columnB,...] #9092

Closed
st1page opened this issue Apr 11, 2023 · 16 comments · Fixed by #10438
Closed

feat: SELECT * EXCEPT [columnA,columnB,...] #9092

st1page opened this issue Apr 11, 2023 · 16 comments · Fixed by #10438
Assignees
Labels
experimental user-facing-changes Contains changes that are visible to users

Comments

@st1page
Copy link
Contributor

st1page commented Apr 11, 2023

It is a SQL grammar supported by Snowflake
It can improve the usability of GroupTopN pattern https://www.risingwave.dev/docs/current/sql-pattern-topn/
Still need discussion.

SELECT * EXCEPT(rank)
  FROM (
    SELECT [column_list], 
      function_name() OVER ([PARTITION BY col1[, col2...]] 
        ORDER BY col1 [ ASC | DESC ][, col2 [ ASC | DESC ]...]) AS rank 
    FROM table_name)
WHERE rank <= N [AND conditions];
@github-actions github-actions bot added this to the release-0.19 milestone Apr 11, 2023
@fuyufjh
Copy link
Member

fuyufjh commented Apr 11, 2023

-1. It sounds very ad-hoc and not part of SQL standard, and it's very easy to work around.

@xxchan
Copy link
Member

xxchan commented Apr 11, 2023

This syntax is from BigQuery. It seems more reasonable for an AP system to support convenient syntax for ad-hoc queries 🤔, and less reasonable for us.

@xxchan
Copy link
Member

xxchan commented Apr 11, 2023

Similar request for adding new syntax: #7506

My main concern is that adding new things may break other things in unexpected ways, especially for SQL, a complex and not well-designed language.

Anyway, such topic might unavoidably involve a lot of bikeshedding, and I agree we should decide the general attitude before talking about specific sugars.

@neverchanje
Copy link
Contributor

neverchanje commented Apr 24, 2023

I found a solution for the specific query you mentioned. Instead of select * in the outer query, we can rewrite this by select * in the inner query and excluding the rank in the outer side:

The original query:

select * from (select v1, v2, row_number() over (order by v1 asc) rn from t) as foo where rn = 1;

The rewritten version:

select v1, v2 from (select *, row_number() over (order by v1 asc) rn from t) as foo where rn = 1;

@lmatz
Copy link
Contributor

lmatz commented May 12, 2023

I think it appears to be some dbt-level stuff, like a macro and users write that and get translated automatically, but still send the original to our Frontend to process. No changes need to be made on our side.

I do agree that it improves user experience.

Edit:
Since so many databases support it natively, changed my mind

Edit:
Also considered TennyZhuang's use case.

@TennyZhuang
Copy link
Contributor

-1. It sounds very ad-hoc and not part of SQL standard, and it's very easy to work around.

I'm modifying a query related to a 35-cols table, and I think it's hard to work around :(

@st1page
Copy link
Contributor Author

st1page commented Jun 9, 2023

          > > #9092

In all well-known database, only BigQuery supports that, but they use EXCEPT keyword :(

Sorry it is my typo 🥵 😿

Originally posted by @st1page in #10265 (comment)

@TennyZhuang TennyZhuang changed the title feat: SELECT * EXCLUDE [columnA,columnB,...] feat: SELECT * EXCEPT [columnA,columnB,...] Jun 9, 2023
@TennyZhuang TennyZhuang changed the title feat: SELECT * EXCEPT [columnA,columnB,...] feat: SELECT * EXCLUDE [columnA,columnB,...] Jun 9, 2023
@TennyZhuang
Copy link
Contributor

So at least both Snowflake and BigQuery support similar things.

@TennyZhuang
Copy link
Contributor

@TennyZhuang
Copy link
Contributor

@xxchan
Copy link
Member

xxchan commented Jun 14, 2023

We can continue to discuss this request now.

@lmatz said:

Since so many databases support it natively, changed my mind

@fuyufjh how do you think?

BTW, I think @neverchanje 's workaround of using select * in the inner query still applies. @TennyZhuang how to you think?

@xxchan
Copy link
Member

xxchan commented Jun 14, 2023

workaround of using select * in the inner query

Well, it only works if we are going to decide the columns to use after the TopN. But maybe we just want to do a TopN and select all columns for later processing.

@st1page st1page changed the title feat: SELECT * EXCLUDE [columnA,columnB,...] feat: SELECT * EXCEPT [columnA,columnB,...] Jun 19, 2023
@wugouzi wugouzi mentioned this issue Jun 20, 2023
7 tasks
@xxchan
Copy link
Member

xxchan commented Jun 20, 2023

BTW, duckdb/snowflake use EXCLUDE

@st1page
Copy link
Contributor Author

st1page commented Jun 20, 2023

BTW, duckdb/snowflake use EXCLUDE

we can implement it too 👀

@xxchan
Copy link
Member

xxchan commented Jun 20, 2023

What do you mean? Isn't EXCEPT the same as EXCLUDE? We need to choose one name. 👀

@st1page
Copy link
Contributor Author

st1page commented Jun 20, 2023

What do you mean? Isn't EXCEPT the same as EXCLUDE? We need to choose one name. eyes

You see, in SQL we can use different word for the same feature, such as "EXCEPT" and "MINUS"

@lmatz lmatz added experimental user-facing-changes Contains changes that are visible to users labels Jun 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental user-facing-changes Contains changes that are visible to users
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants