Skip to content

Commit

Permalink
fix: cte syntax bug (#912)
Browse files Browse the repository at this point in the history
  • Loading branch information
brennanjl authored Aug 7, 2024
1 parent 0f7de25 commit 22bdf85
Show file tree
Hide file tree
Showing 4 changed files with 1,180 additions and 1,067 deletions.
17 changes: 10 additions & 7 deletions parse/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,14 +1265,17 @@ func (s *sqlAnalyzer) VisitCommonTableExpression(p0 *CommonTableExpression) any
panic("expected query to return attributes")
}

if len(p0.Columns) != len(rel) {
s.errs.AddErr(p0, ErrResultShape, "expected %d columns, received %d", len(p0.Columns), len(rel))
return nil
}
// cte columns are optional
if len(p0.Columns) > 0 {
if len(p0.Columns) != len(rel) {
s.errs.AddErr(p0, ErrResultShape, "expected %d columns, received %d", len(p0.Columns), len(rel))
return nil
}

// rename the columns and add the relation to the outer scope
for i, col := range p0.Columns {
rel[i].Name = col
// rename the columns and add the relation to the outer scope
for i, col := range p0.Columns {
rel[i].Name = col
}
}

s.sqlCtx.outerRelations = append(s.sqlCtx.outerRelations, &Relation{
Expand Down
Loading

0 comments on commit 22bdf85

Please sign in to comment.