-
Notifications
You must be signed in to change notification settings - Fork 475
docs: Add WITH ORDINALITY
#33317
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
docs: Add WITH ORDINALITY
#33317
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm -- left a suggestion.
doc/user/data/sql_funcs.yml
Outdated
Table functions evaluate to a set of rows, rather than a single expression. | ||
You can also add `WITH ORDINALITY` after the closing parenthesis of a table function call in a `FROM` clause. | ||
This causes an `ordinality` column to appear, which is a 1-based numbering of the output rows of each call of | ||
the table function. For example, `unnest(list) WITH ORDINALITY` numbers the unnested elements of each input list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe?
Table functions evaluate to a set of rows, rather than a single expression. | |
You can also add `WITH ORDINALITY` after the closing parenthesis of a table function call in a `FROM` clause. | |
This causes an `ordinality` column to appear, which is a 1-based numbering of the output rows of each call of | |
the table function. For example, `unnest(list) WITH ORDINALITY` numbers the unnested elements of each input list. | |
Table functions evaluate to a set of rows rather than a single expression. | |
{{< annotation type="WITH ORDINALITY" >}} | |
You can also add `WITH ORDINALITY` after the table function call in a `FROM` | |
clause. This causes an `ordinality` column to appear, which is a 1-based | |
numbering of the output rows of each call of the table function. | |
For example, `SELECT * FROM unnest(LIST[5,10]) WITH ORDINALITY AS | |
list_item;` (or `SELECT * FROM unnest(LIST[5,10]) AS list_item WITH | |
ORDINALITY;`) includes the `ordinality` column containing the 1-based | |
numbering of the unnested elements. | |
{{</ annotation >}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I've made some further adjustments:
- "after the table function call" -> "after a table function call", because there can be multiple table function calls in a FROM clause.
- I've dropped the "(or
SELECT * FROM unnest(LIST[5,10]) AS list_item WITH ORDINALITY;
)", because this is not a syntax that I'd like people to use. I think no other system allows this. We used to allow only this syntax, but that was just a parser glitch. - "of the unnested elements" -> "of the unnested items", to align the wording with the above
list_item
column name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me!
51f0fb1
to
7f405e8
Compare
Thank you for the review! |
Not merging yet. I'll merge it, when the fixes go out next week Aug 21. |
I've just realized that |
762e175
to
7f7c9df
Compare
doc/user/data/sql_funcs.yml
Outdated
|
||
{{</ annotation >}} | ||
|
||
{{< annotation type="ROWS FROM" >}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ... I wonder if most of the content should be actually an idiomatic SQL thing for ROWS FROM and we just link to that from here instead of a whole annotation thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the idiomatic SQL pages are for when there is a particular preferred way of expressing a thing in Materialize, and it is possibly different from other systems' preferred way. ROWS FROM
is not like that: you can simply write it the same way in Materialize as in other systems.
Postgres documents both WITH ORDINALITY
and ROWS FROM
in the SELECT page, at the FROM
clause (at function_name
):
https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM
We could do the same, i.e., expand table_expr
in our SELECT page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, got it. In that case, 100% agree with your suggestion to move these to our select page and just link to there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll do that move now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, how about we create a separate page just for table function calls? The problem is that both table_expr
/table_ref
in the SELECT page and table_ref
in the JOIN page would need to allow WITH ORDINALITY and ROWS FROM, but we don't want to repeat this on both pages. So, we could create a separate page, and just link to there from the SELECT page and JOIN page (and table function list) where we explain table_expr
. (table_ref
should be table_expr
everywhere.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a separate page would be similar also to how the various extra things around aggregation function calls are explained in separate pages, e.g.
- The FILTER clause: https://materialize.com/docs/sql/functions/filters/
- ORDER BY inside an aggregation: https://materialize.com/docs/sql/functions/list_agg/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works. Redoing the SELECT/JOIN/CTE pages are on my todo list; so, keeping this change clean works for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please check again @kay-kim ?
I've pushed a commit for the above:
- Created a new table functions page, moved the WITH ORDINALITY and ROWS FROM content to it, plus added some more content, and linked it in a few places.
- fixed some minor things:
- The SELECT page had
table_ref
andtable_expr
inconsistently. Now it hastable_expr
in both places. (It would have been good to also modify the sametable_ref
totable_expr
in the JOIN page, but I didn't do that, because I would have needed to touch the grammar, butsql-grammar/generate.sh
was not really working for me.) - I've fixed the most pressing part of https://github.com/MaterializeInc/database-issues/issues/8311#issuecomment-3201977113
- The SELECT page had
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you 😍 😍😍 ... Added a patch with some minor tweaks.
2656e5c
to
8e85e6a
Compare
8e85e6a
to
2c82dae
Compare
2b1557f
to
0dcf8cf
Compare
Thank you! I'll merge it on Thursday after the release is rolled out. |
As it says on the tin.
Our support for
WITH ORDINALITY
used to have serious issues, so it was better that it was not mentioned in our docs up to now. But we've fixed these issues recently (#33163, #33291, #33272), so it's time to add it to the docs.Motivation
Tips for reviewer
Checklist
$T ⇔ Proto$T
mapping (possibly in a backwards-incompatible way), then it is tagged with aT-proto
label.