Fix ParamRef.Number always 0 for $N bind parameters - #1
Open
notthelewis wants to merge 1 commit into
Open
notthelewis wants to merge 1 commit into
notthelewis wants to merge 1 commit into
Conversation
parserLexer.Lex() copies lexer token data into the yacc semantic value via a switch on token type, but had no case for PARAM ($1, $2, ...). The lexer (Lexer.lexParam) correctly scans the parameter's number into Token.Ival, but without a matching case it fell through to default, which only ever sets lval.str — so lval.ival stayed at its zero value and every ParamRef parsed with Number 0 regardless of its actual position in the query. Adds a case copying tok.Ival into lval.ival, plus a regression test covering repeated/multiple parameters in both the target list and a WHERE clause.
|
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.
Summary
parserLexer.Lex()inparser/parse.gocopies lexer token data into the yacc semantic value via a switch on token type, but had nocase PARAM:. The lexer (Lexer.lexParam) correctly scans a bind parameter's number intoToken.Ival, but without a matching case it fell through todefault, which only ever setslval.str.lval.ivalwas left at its zero value, so every$Nparsed asParamRef{Number: 0}regardless of its actual position.case PARAM: lval.ival = tok.Ival.Found while building a downstream tool that translates parsed Postgres SQL into another dialect and needed the actual parameter ordinals preserved.
Test plan
parser/parsertest/paramref_test.go, covering a query with a repeated parameter ($1) and a second one ($2) across both the target list and aWHEREclause.go test ./...passes locally (all existing packages, includingparsertest,pgregress, andtests/grammar).