diff --git a/go/vt/sqlparser/ast_rewriting.go b/go/vt/sqlparser/ast_rewriting.go index 743b01a92aa..9cdf94de805 100644 --- a/go/vt/sqlparser/ast_rewriting.go +++ b/go/vt/sqlparser/ast_rewriting.go @@ -571,10 +571,17 @@ func (er *astRewriter) funcRewrite(cursor *Cursor, node *FuncExpr) { if !found || (bindVar == DBVarName && !er.shouldRewriteDatabaseFunc) { return } + + // Don't rewrite `last_insert_id` function call if an argument is given + if len(node.Exprs) > 0 && node.Name.Lowered() == "last_insert_id" { + return + } + if len(node.Exprs) > 0 { er.err = vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "Argument to %s() not supported", node.Name.Lowered()) return } + cursor.Replace(bindVarExpression(bindVar)) er.bindVars.AddFuncResult(bindVar) } diff --git a/go/vt/sqlparser/ast_rewriting_test.go b/go/vt/sqlparser/ast_rewriting_test.go index 6fe59acbc85..dbc938e6ea8 100644 --- a/go/vt/sqlparser/ast_rewriting_test.go +++ b/go/vt/sqlparser/ast_rewriting_test.go @@ -67,6 +67,9 @@ func TestRewrites(in *testing.T) { in: "SELECT @@enable_system_settings", expected: "SELECT :__vtenable_system_settings as `@@enable_system_settings`", sessionEnableSystemSettings: true, + }, { + in: "SELECT last_insert_id(10)", + expected: "SELECT last_insert_id(10)", }, { in: "SELECT last_insert_id()", expected: "SELECT :__lastInsertId as `last_insert_id()`",