Skip to content
Draft
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: 6 additions & 2 deletions src/40select.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ yy.Select = class Select {
s += 'DISTINCT ';
}
if (this.top) {
s += 'TOP ' + this.top.value + ' ';
s += 'TOP ' + this.top.toString() + ' ';
if (this.percent) {
s += 'PERCENT ';
}
Expand Down Expand Up @@ -245,7 +245,11 @@ yy.Select = class Select {

// 10. Compile TOP/LIMIT/OFFSET/FETCH clause
if (this.top) {
query.limit = this.top.value;
if (this.top instanceof yy.ParamValue) {
query.limitParam = this.top.param;
} else {
query.limit = this.top.value;
}
} else if (this.limit) {
if (this.limit instanceof yy.ParamValue) {
query.limitParam = this.limit.param;
Expand Down
6 changes: 3 additions & 3 deletions src/alasqlparser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -849,9 +849,9 @@ SelectModifier
;

TopClause
: TOP NumValue PERCENT?
: TOP (NumValue|ParamValue) PERCENT?
{ $$ = {top: $2, percent:(typeof $3 != 'undefined'?true:undefined)}; }
| TOP LPAR NumValue RPAR
| TOP LPAR (NumValue|ParamValue) RPAR
{ $$ = {top: $3}; }
| { $$ = undefined; }
;
Expand Down Expand Up @@ -1263,7 +1263,7 @@ LimitClause
: { $$ = undefined; }
| LIMIT (NumValue|ParamValue) OffsetClause
{ $$ = {limit:$2}; yy.extend($$, $3); }
| OFFSET NumValue ROWS? FETCH NEXT? NumValue ROWS? ONLY?
| OFFSET (NumValue|ParamValue) ROWS? FETCH NEXT? (NumValue|ParamValue) ROWS? ONLY?
{ $$ = {limit:$6,offset:$2}; }
;

Expand Down
Loading