Prepend raw fields with table/subquery name in rendered SQL
Currently, it doesn't seem like raw fields in a select statement hold any information on the table/subquery they're used in. This results in subsequent usage of these fields elsewhere rendering to SQL as
"field_name"
instead of "alias"."field_name"
.
This actually causes issues when you have overlapping field names in sql in your joins.
Example:
will result in an error
with the following workaround
This behavior persists through subsequent subqueries where
will result in a similar error due to the ambiguity between someTable.date
and sq2.balanceDate
.2 Replies
I've seen at least one other person pointing to the behavior before.
https://discordapp.com/channels/1043890932593987624/1148051375167643698
I just cheched github and the issue is there, and you actually commented on it.
So it is and issue. Looks like the current workaround might look like this: https://discordapp.com/channels/1043890932593987624/1148051375167643698/1148079123017760828
That doesn't quite work in my case, where the raw sql field is in a subquery/CTE and collides with the name of of another table/subquery/cte. You have to prefix it with the subquery/CTE name manually every time it's used or keep track of and use different names for every such field like
.as("balances_date")
and .as("transaction_date")
.