sql: make the table reference syntax carry its alias, if any #17031
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch extends the numeric table reference syntax (e.g.
[123]
)with the ability to give the source and its columns an alias.
The following new syntax forms are allowed:
[123(1,2,3) as t]
the same as[123(1,2,3)] as t
.[123 as t(x,y,z)]
the same as[123] as t(x,y,z)
.[123(1,2,3) as t(x,y,z)]
the same as[123(1,2,3]) as t(x,y,z)
.Meanwhile things like
[123 as t] as u
are still possible.Reminder: the previously supported syntax
[123(1,2,3)]
is a datasource providing only columns 1,2,3 from table 123. Its column names
are those listed in the table descriptor.
The new syntax forms are introduced in preparation of a subsequent
patch to enhance the handling of view descriptors.
Also,the new syntax captures the alias definition (AS clause) inside
the square brackets, as we plan to replace table names by this square
bracket syntax, and the replacement must syntactically fit in a way
that does not cause grammar error. In a table expression of the form
foo as t
, a naive replacement using[123] as foo as t
would besyntactically invalid, whereas
[123 as foo] as t
is valid.I am extracting this functionality from the more complex #15388, because I would like to rebase #16884 on top of it.