Skip to content

fix(db): read PostgreSQL LIMIT ALL as the statement's own unlimited bound - #1931

Open
niukanen1 wants to merge 1 commit into
libredb:mainfrom
niukanen1:fix/limit-all-bound-1926
Open

niukanen1 wants to merge 1 commit into
libredb:mainfrom
niukanen1:fix/limit-all-bound-1926

Conversation

@niukanen1

Copy link
Copy Markdown
Contributor

Description

PostgreSQL documents LIMIT { count | ALL }, but the shared query limiter only recognized a numeric LIMIT n for this dialect, so SELECT * FROM t LIMIT ALL was read as unbounded and rewritten to LIMIT ALL LIMIT 500 - two LIMIT clauses, which PostgreSQL rejects (#1926). The word is now declared on the Postgres grammar's nonNumericRowBounds, the same route Snowflake's NULL took (SF-021): the statement's own unlimited bound is detected, nothing is appended, and forceLimit replaces it.

ALL is accepted for the LIMIT count only - the FETCH spelling has no ALL arm in PostgreSQL's grammar - so a FETCH FIRST ALL ROWS ONLY is still the engine's own refusal, just without a second bound appended to it. Spark's documented behavior (it refuses LIMIT ALL itself) is unchanged.

Fixes #1926

Verification

  • bun tests/run-tests.ts tests/unit/db/query-limiter.test.ts - new describe with the case variants (ALL/all/All), a trailing comment, a CTE, forceLimit, literal/comment false positives, and eight other dialects reading LIMIT ALL exactly as before; all 307 pass
  • bun tests/run-tests.ts tests/unit/db/sql-grammar/golden.test.ts - golden snapshot regenerated for the one grammar field
  • bun tests/run-tests.ts tests/integration/db/postgres-provider.test.ts - prepareQuery() keeps LIMIT ALL untouched; all pass
  • tsc --noEmit and biome check clean

@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@niukanen1

Copy link
Copy Markdown
Contributor Author

The VS Code Extension Smoke (windows-latest) failure is a download abort while fetching the VS Code 1.123.2 archive (251 MB, three retries, "Error: aborted") - the same smoke subset passes on macos-latest, and the change does not touch the extension. Everything else is green.

@niukanen1
niukanen1 force-pushed the fix/limit-all-bound-1926 branch from a380beb to 9af9d88 Compare October 24, 2026 10:53
@niukanen1

Copy link
Copy Markdown
Contributor Author

Rebased onto the current main (1d5f63b) to clear the conflict: kept the LIMIT ALL tests next to the CTE tests that landed in the meantime and merged both grammar keys into the golden line

This branch has not been deployed

No deployments
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.

[BUG] Query limiter does not treat PostgreSQL LIMIT ALL as a bound and emits invalid SQL (LIMIT ALL LIMIT 500)

1 participant