Repository navigation
fix(psql): include closing END in CASE expression span - #779
Open
akashchamp wants to merge 1 commit into
Open
akashchamp wants to merge 1 commit into
akashchamp wants to merge 1 commit into
Conversation
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
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.
Fixes #767.
The walker built the span of a
CASEexpression from its child nodes, so it ended at theELSEresult and never included the closingEND. ForUPDATE ... SET col = CASE ... END WHERE ...that meant the generatedAppendSetrange stopped beforeEND, and the built query failed withsyntax error at or near "WHERE". The same happened to aCASEin aWHEREclause.This adds a
walkCaseExprthat extends the span to the matchingENDtoken (counting nestedCASE/ENDpairs), plus a CHANGELOG entry.Verification:
TestCaseExprEndingen/bobgen-psql/driver/parserchecks theAppendSet/AppendWheretext for aCASEinSET, a nestedCASE, and aCASEinWHERE. All three fail onmainand pass with the fix.AppendSetwassubExpr(22, 91)(... ELSE i.name) onmain, as reported, and is nowsubExpr(22, 99)(... ELSE i.name END).go test ./gen/bobgen-psql/...,go vet,gofumpt -landgolangci-lint runon the parser package all pass. Docker isn't available on my machine, soTestDrivercouldn't start its Postgres container and skipped the DB-backed generation.