Repository navigation
DuckDB: support LIMIT 10% and TABLESAMPLE without a method - #2802
Merged
manticore-projects merged 2 commits intoOct 13, 2026
Merged
manticore-projects merged 2 commits into
manticore-projects merged 2 commits into
Conversation
guizmaii
marked this pull request as ready for review
October 13, 2026 09:45
27 tasks
- `LIMIT 10%` and `LIMIT 10 PERCENT` set the new `Limit.percentUnit`. Inside a LIMIT, a `%` followed by the end of the clause is the unit, not a modulo; `LIMIT 10 % 3` and `LIMIT a % offset` are unchanged. - TABLESAMPLE takes DuckDB's optional method and reservoir, as USING SAMPLE already does: `TABLESAMPLE 10%`, `TABLESAMPLE reservoir(10 ROWS)`. - A table function keeps and prints its sample clause: `range(10) r USING SAMPLE 10%` used to lose it.
- LIMIT scans its clause once for the top-level % followed by its end, and the Pratt loop stops at that token only, so `LIMIT a % offset + 1` and modulos nested in sub-selects are unchanged. - OFFSET ends the clause only before a value, FETCH only before FIRST or NEXT. - After DuckDB's TABLESAMPLE n, OFFSET belongs to the query. - The unit is printed after NULL and ALL too.
guizmaii
force-pushed
the
duckdb-limit-percent-tablesample
branch
from
October 13, 2026 10:50
f26ed7f to
4566175
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For DuckDB's percentage limits (docs) and
TABLESAMPLEforms (docs).LIMIT 10%,LIMIT 40 PERCENT,LIMIT 50% OFFSET 2LimitwithgetPercentUnit()%/PERCENTTABLESAMPLE 10%,TABLESAMPLE 10 ROWS,TABLESAMPLE reservoir(10 ROWS) REPEATABLE (1)SampleClause, method optional as forUSING SAMPLEFROM range(10) r USING SAMPLE 10%%directly followed by the end of the clause (end of input,;,), a set operator, OFFSET followed by a value, FETCH FIRST/NEXT); the Pratt loop stops at that token only. That%used to be a modulo missing its right operand, i.e. an error, soLIMIT 10 % 3,LIMIT a % offset + 1(a column named offset) and modulos in nested sub-selects parse as before. After DuckDB'sTABLESAMPLE n,OFFSETbelongs to the query.TableFunctionimplementedsetSampleClauseas a no-op; it now stores and prints the clause.checkGrammarAmbiguity: no conflicts../gradlew check: 10,118 tests, 0 failures. On ~9,760 statements extracted from this repository's tests, results are identical to master.test/sql, 70,729 statements): 50 more parse, none less.