-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: allow unaliased subqueries within UDFs #96375
Comments
Postgres doesn't allow unaliased subqueries in So the only decision that I can see us needing to make is whether we remove support for unaliased subqueries in |
Actually, it might be possible to "assign" a unique alias for unaliased subqueries when the UDF is created, removing any ambiguity from the rewritten function body. |
[idea from triage] could we come up with a unique alias and use that to fix the UDF problem? |
Here's an explanation of why we currently disallow unaliased subqueries in UDFs: #95710 (review) |
Yes this seems to be the preferable approach. |
It looks like postgres doesn't qualify the column names during star expansion for views, but it does for UDFs:
|
In both cases, the column names are not qualified. It's always valid for a pg projection to contain multple columns with the same name, for example The extra thing that happens with CREATE VIEW is that the DDL code validates that the resulting table descriptor has unique column names. This is not needed in your UDF example because it returns a RECORD type, which doesn't include column labels. There's no additional uniqueness check for the column names in that case. |
The output of \df+ looks like this for that function:
|
There is a compatibility difference with postgres for queries with ambiguous columns.
Examples that fail in postgres with "subquery in FROM must have an alias" but not crdb:
The following example fails correctly in crdb with "column reference "a" is ambiguous":
Jira issue: CRDB-24094
The text was updated successfully, but these errors were encountered: