Skip to content

Commit e006f7f

Browse files
committed
duckdb: preserve OFFSET parameters with a percentage LIMIT
1 parent 3ad8b20 commit e006f7f

5 files changed

Lines changed: 36 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"command": "analyze",
3+
"args": ["--dialect", "duckdb", "--schema", "schema.sql", "query.sql"],
4+
"contexts": ["base"]
5+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- name: Page :many
2+
SELECT id FROM readings ORDER BY id LIMIT 50% OFFSET $1;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CREATE TABLE readings (id INTEGER NOT NULL);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"name": "Page",
4+
"cmd": ":many",
5+
"columns": [
6+
{
7+
"name": "id",
8+
"type": {
9+
"name": "integer"
10+
},
11+
"table": "readings"
12+
}
13+
],
14+
"params": [
15+
{
16+
"number": 1,
17+
"column": {
18+
"name": "",
19+
"type": {
20+
"name": "integer"
21+
}
22+
}
23+
}
24+
]
25+
}
26+
]

‎internal/engine/duckdb/convert.go‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,8 @@ func (c *cc) applyModifiers(stmt *ast.SelectStmt, mods []dw.ResultModifier) {
7575
case *dw.OrderModifier:
7676
stmt.SortClause = c.convertOrderBys(m.Orders)
7777
case *dw.LimitModifier:
78-
// LIMIT n% has no row-count equivalent.
79-
if m.LimitType == dw.LimitPercentage {
80-
continue
81-
}
82-
if m.Limit != nil {
78+
// LIMIT n% has no row-count equivalent, but its OFFSET counts rows.
79+
if m.Limit != nil && m.LimitType != dw.LimitPercentage {
8380
stmt.LimitCount = c.convertExpr(m.Limit)
8481
}
8582
if m.Offset != nil {

0 commit comments

Comments
 (0)