cancel
Showing results for 
Search instead for 
Did you mean: 
Warehousing & Analytics
Engage in discussions on data warehousing, analytics, and BI solutions within the Databricks Community. Share insights, tips, and best practices for leveraging data for informed decision-making.
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with Lateral Column Alias (LCA)

paulocorrea
New Contributor II

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?

 

paulocorrea_0-1722351334548.png

 

paulocorrea_1-1722351445234.png

3 REPLIES 3

paulocorrea
New Contributor II

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.

paulocorrea
New Contributor II

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:

 

paulocorrea_0-1722518837765.png

 

ClausStier
New Contributor II

Hi @Kaniz_Fatma,

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

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group