Skip to content

fix(psql): include closing END in CASE expression span - #779

Open
akashchamp wants to merge 1 commit into
stephenafamo:mainfrom
akashchamp:fix-psql-case-expr-end
Open

akashchamp wants to merge 1 commit into
stephenafamo:mainfrom
akashchamp:fix-psql-case-expr-end

Conversation

@akashchamp

Copy link
Copy Markdown

Fixes #767.

The walker built the span of a CASE expression from its child nodes, so it ended at the ELSE result and never included the closing END. For UPDATE ... SET col = CASE ... END WHERE ... that meant the generated AppendSet range stopped before END, and the built query failed with syntax error at or near "WHERE". The same happened to a CASE in a WHERE clause.

This adds a walkCaseExpr that extends the span to the matching END token (counting nested CASE/END pairs), plus a CHANGELOG entry.

Verification:

  • New TestCaseExprEnd in gen/bobgen-psql/driver/parser checks the AppendSet/AppendWhere text for a CASE in SET, a nested CASE, and a CASE in WHERE. All three fail on main and pass with the fix.
  • Ran the issue's exact query through the walker: AppendSet was subExpr(22, 91) (... ELSE i.name) on main, as reported, and is now subExpr(22, 99) (... ELSE i.name END).
  • go test ./gen/bobgen-psql/..., go vet, gofumpt -l and golangci-lint run on the parser package all pass. Docker isn't available on my machine, so TestDriver couldn't start its Postgres container and skipped the DB-backed generation.

The walker computed the span of a CASE expression from its child nodes
only, so it stopped at the ELSE result and left out the closing END.
For a query such as UPDATE ... SET col = CASE ... END WHERE ..., the
generated AppendSet range dropped the END and the built query was
invalid SQL.

Extend the span of a CaseExpr to its matching END token.

Fixes stephenafamo#767
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.

bobgen-psql: generated queries code for UPDATE ... SET col = CASE ... END ... WHERE drops the closing END, producing invalid SQL

1 participant