Skip to content

fix(coreanalyzer): Infer parameter names in LIMIT ? OFFSET ? clauses for SQLite and MySQL - #4731

Open
manuelschoene wants to merge 2 commits into
sqlc-dev:mainfrom
manuelschoene:fix/core-limit-offset-parameter-names
Open

manuelschoene wants to merge 2 commits into
sqlc-dev:mainfrom
manuelschoene:fix/core-limit-offset-parameter-names

Conversation

@manuelschoene

Copy link
Copy Markdown

Under the core analyzer (SQLCEXPERIMENT=coreanalyzer), LIMIT and OFFSET placeholders were generated as Column1/Column2 instead of Limit/Offset. The legacy compiler names them in resolve.go; the bridge into the analysis core had no equivalent, and the core leaves them unnamed because the database reports no name for them.

Fixes #4730.

Fix

  • limitParamNames in internal/compiler/parse_core.go finds the placeholders that are a whole LimitCount or LimitOffset of a SELECT, UPDATE or DELETE and names them limit and offset.
  • Placeholders are named by the clause they end up in, not by their position. SQLite parses LIMIT x, y as LIMIT y OFFSET x, so the comma form gets Offset, Limit in the right order.
  • The name goes into a new compiler.Parameter.InferredName rather than onto the parameter's column, and pluginQueryParam applies it only when the column has no name. The name therefore only reaches codegen: sqlc analyze keeps printing what the analysis reports ("name": ""), which the analyze_* cases and goldeneye check against the database. Writing it onto the column changed analyze_expressions/{sqlite,clickhouse} and analyze_percent_offset/duckdb; core: carry enums, views and missing placeholders through the analysis core #4614 ran into the same thing when it tried naming them in the core.
  • sqlc.arg() / @name in a LIMIT still wins over the inferred name.

Tests

New case select_limit_comma/sqlite covers the comma form, where the first placeholder is the offset, so a fix that names placeholders by position would swap the two.

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.

core: LIMIT/OFFSET parameters named Column1/Column2 instead of Limit/Offset

1 participant