Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pegjs/sqlite.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,14 @@ set_op
return s ? `union ${s.toLowerCase()}` : 'union'
}

select_core
= select_stmt
/ v:value_clause {
return { type: 'values', values: v.values }
}

union_stmt
= head:select_stmt tail:(__ set_op __ select_stmt)* __ ob: order_by_clause? __ l:limit_clause? {
= head:select_core tail:(__ set_op __ select_core)* __ ob: order_by_clause? __ l:limit_clause? {
let cur = head
for (let i = 0; i < tail.length; i++) {
cur._next = tail[i][3]
Expand Down
9 changes: 9 additions & 0 deletions test/sqlite.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,13 @@ describe('sqlite', () => {
expect(getParsedSql(sql)).to.be.equal(sql)
});
});
it('should support CTE with VALUES', () => {
const sql = `WITH RECURSIVE cnt(x) AS (
VALUES(1)
UNION ALL
SELECT x+1 FROM cnt WHERE x < 10
)
SELECT x FROM cnt;`
expect(getParsedSql(sql)).to.be.equal(`WITH RECURSIVE "cnt"("x") AS ((1)) SELECT "x" FROM "cnt"`)
})
})