Closed ananis25 closed 2 years ago
@xitology - curious why the extra aliasing is needed when translating the Knot
nodes too (Link
). Could you please mention an example where it would cause a bug?
I believe it's impossible to trigger this bug with a Knot
node. Knot
is an intermediate node (created by Iterate
) that generates a WITH RECURSIVE
clause. I updated assemble
for KnotNode
for consistency so that the generated SQL is the same for both non-recursive WITH
and WITH RECURSIVE
clauses. However since it is impossible to refer to the Iterate
node using From
, you cannot use Join
to duplicate the node and trigger this bug.
In the compiled SQL string, the CTE tables are not aliased. This results in an invalid query when doing something like a self join.
Repro
Possible Fix
A
From
node referencing a CTE subquery is specialized to aFromReference
node during the annotation pass. Looking at theassemble
routine forFromTable
, an alias is created everytime the node is encountered. We could port over the same logic toFromReference
.I would commit a PR but I'm not yet comfortable with the Julia workflow.