Skip to content

Support runtime parameters in TOP and FETCH row-limiting clauses - #2530

Draft
mathiasrw with Copilot wants to merge 3 commits into
developfrom
copilot/support-fetch-and-top-parameters
Draft

Support runtime parameters in TOP and FETCH row-limiting clauses#2530
mathiasrw with Copilot wants to merge 3 commits into
developfrom
copilot/support-fetch-and-top-parameters

Conversation

Copilot AI commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

This extends the row-limiting parameter support added for LIMIT/OFFSET to also cover TOP and FETCH, so compiled SQL can be reused independent of the requested row count. The change applies to both direct execution and precompiled queries.

  • Parser updates

    • Allow ParamValue in TOP ?, TOP ($name), and OFFSET ... FETCH ... forms.
    • Keep existing literal-based syntax unchanged.
  • Select compilation/runtime

    • Route TOP through the same deferred limit resolution path already used by parameterized LIMIT.
    • Preserve existing OFFSET handling while enabling parameterized FETCH limits.
  • Precompile parity

    • Carry limitParam / offsetParam metadata into precompile/index.js so generated query wrappers resolve row limits at execution time instead of compile time.
  • Regression coverage

    • Add a focused issue regression test covering:
      • positional params in TOP and FETCH
      • named params in TOP and FETCH
      • reuse of compiled statements with different parameter values
alasql('SELECT TOP ? a FROM one ORDER BY a ASC', [2]);
alasql('SELECT a FROM one ORDER BY a ASC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY', [1, 2]);

const stmt = alasql.compile('SELECT TOP $lim a FROM one ORDER BY a ASC');
stmt({ lim: 3 });

Copilot AI linked an issue Aug 20, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add support for parameters in FETCH and TOP Support runtime parameters in TOP and FETCH row-limiting clauses Aug 20, 2026
Copilot AI requested a review from mathiasrw August 20, 2026 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support parameters in FETCH and and TOP

2 participants