Skip to content

Commit

Permalink
[release-21.0] Fail assignment expressions with the correct message (#…
Browse files Browse the repository at this point in the history
…17752) (#17776)

Signed-off-by: Manan Gupta <[email protected]>
Co-authored-by: Manan Gupta <[email protected]>
Co-authored-by: Manan Gupta <[email protected]>
  • Loading branch information
3 people authored Feb 14, 2025
1 parent 312ce23 commit 6d984ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go/vt/sqlparser/ast_rewriting.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ func (er *astRewriter) rewriteAliasedExpr(node *AliasedExpr) (*BindVarNeeds, err

func (er *astRewriter) rewriteDown(node SQLNode, _ SQLNode) bool {
switch node := node.(type) {
case *AssignmentExpr:
er.err = vterrors.VT12001("Assignment expression")
return false
case *Select:
er.visitSelect(node)
case *PrepareStmt, *ExecuteStmt:
Expand Down
6 changes: 6 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1327,9 +1327,15 @@ var (
input: "update /* a.b */ a.b set b = 3",
}, {
input: "update a.b set d = @v := d + 7 where u = 42",
// Assignment expresions aren't supported, so we skip the normalizer test.
// We only support parsing these expressions.
ignoreNormalizerTest: true,
}, {
input: "select @topic3_id:= 10103;",
output: "select @topic3_id := 10103 from dual",
// Assignment expresions aren't supported, so we skip the normalizer test.
// We only support parsing these expressions.
ignoreNormalizerTest: true,
}, {
input: "update /* list */ a set b = 3, c = 4",
}, {
Expand Down
5 changes: 5 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/unsupported_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@
"query": "select @val := 42",
"plan": "VT12001: unsupported: Assignment expression"
},
{
"comment": "Assignment expression in on duplicate clause",
"query": "insert into unsharded (id) values (@val := 42)",
"plan": "VT12001: unsupported: Assignment expression"
},
{
"comment": "Assignment expression in union statements",
"query": "select @val := 42 union select 1",
Expand Down

0 comments on commit 6d984ad

Please sign in to comment.