Issue with Lateral Column Alias (LCA)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 08:06 AM
I have a query using LCA. When referencing another table that has a column with the same name as the column used as LCA, the behavior of the query changes and it starts referencing the table column instead of the column that is already in the select and was previously used. Is there a way to ensure that the column used will always be the one previously defined in the select itself?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 06:16 AM
Hi @Retired_mod,
But in this case I would have to qualify the column that was defined in the select because it is the one that was no longer used when adding a table in the join that has exactly the same column name.
I don't know if there is a standard identifier that can be used to indicate that the column I am referencing is the LCA.
I got around it by adding a 'local -' prefix to the name of each column, but I found Databricks' behavior to be too risky in this case, since including a new column in a table can change the behavior of existing queries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2024 06:28 AM
See this other example. The only change was the inclusion of a new table with columns with the same name as the columns defined in the select:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2024 03:59 AM
we had the same problem as @paulocorrea.
That's why it would be correct for to me to throw an error on ambiguous columns and the LCA could/must be addressed with a default identifier.
Thanks