@@ -678,7 +678,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
678678 if b .options .insideDataSource && b .setReturnType .Family () == types .TupleFamily {
679679 retNextScope = b .ob .expandRoutineTupleIntoCols (retNextScope )
680680 }
681- b .appendBodyStmtFromScope (& retCon , retNextScope , "" /* stmtTag */ )
681+ b .appendBodyStmtFromScope (& retCon , retNextScope , nil /* stmt */ )
682682 b .appendPlpgSQLStmts (& retCon , stmts [i + 1 :])
683683 return b .callContinuation (& retCon , s )
684684
@@ -720,7 +720,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
720720 if ! b .options .insideDataSource && b .setReturnType .Family () == types .TupleFamily {
721721 retQueryScope = b .ob .combineRoutineColsIntoTuple (retQueryScope )
722722 }
723- b .appendBodyStmtFromScope (& retCon , retQueryScope , t .SqlStmt . StatementTag () )
723+ b .appendBodyStmtFromScope (& retCon , retQueryScope , t .SqlStmt )
724724 b .appendPlpgSQLStmts (& retCon , stmts [i + 1 :])
725725 return b .callContinuation (& retCon , s )
726726
@@ -949,7 +949,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
949949 // crdb_internal.plpgsql_raise builtin function.
950950 con := b .makeContinuation ("_stmt_raise" )
951951 con .def .Volatility = volatility .Volatile
952- b .appendBodyStmtFromScope (& con , b .buildPLpgSQLRaise (con .s , b .getRaiseArgs (con .s , t )), "" /* stmtTag */ )
952+ b .appendBodyStmtFromScope (& con , b .buildPLpgSQLRaise (con .s , b .getRaiseArgs (con .s , t )), nil /* stmt */ )
953953 b .appendPlpgSQLStmts (& con , stmts [i + 1 :])
954954 return b .callContinuation (& con , s )
955955
@@ -970,7 +970,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
970970 if len (t .Target ) == 0 {
971971 // When there is no INTO target, build the SQL statement into a body
972972 // statement that is only executed for its side effects.
973- b .appendBodyStmtFromScope (& execCon , stmtScope , t .SqlStmt . StatementTag () )
973+ b .appendBodyStmtFromScope (& execCon , stmtScope , t .SqlStmt )
974974 b .appendPlpgSQLStmts (& execCon , stmts [i + 1 :])
975975 return b .callContinuation (& execCon , s )
976976 }
@@ -1028,7 +1028,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
10281028 intoScope = b .callContinuation (& retCon , intoScope )
10291029
10301030 // Step 3: call the INTO continuation from the parent scope.
1031- b .appendBodyStmtFromScope (& execCon , intoScope , t .SqlStmt . StatementTag () )
1031+ b .appendBodyStmtFromScope (& execCon , intoScope , t .SqlStmt )
10321032 return b .callContinuation (& execCon , s )
10331033
10341034 case * ast.Open :
@@ -1068,7 +1068,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
10681068 // Cursors with mutations are invalid.
10691069 panic (cursorMutationErr )
10701070 }
1071- b .appendBodyStmtFromScope (& openCon , openScope , query . StatementTag () )
1071+ b .appendBodyStmtFromScope (& openCon , openScope , query )
10721072 b .appendPlpgSQLStmts (& openCon , stmts [i + 1 :])
10731073
10741074 // Build a statement to generate a unique name for the cursor if one
@@ -1078,7 +1078,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
10781078 nameCon := b .makeContinuation ("_gen_cursor_name" )
10791079 nameCon .def .Volatility = volatility .Volatile
10801080 nameScope := b .buildCursorNameGen (& nameCon , t .CurVar )
1081- b .appendBodyStmtFromScope (& nameCon , b .callContinuation (& openCon , nameScope ), "" /* stmtTag */ )
1081+ b .appendBodyStmtFromScope (& nameCon , b .callContinuation (& openCon , nameScope ), nil /* stmt */ )
10821082 return b .callContinuation (& nameCon , s )
10831083
10841084 case * ast.Close :
@@ -1118,7 +1118,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
11181118 closeScope := closeCon .s .push ()
11191119 b .ob .synthesizeColumn (closeScope , closeColName , types .Int , nil /* expr */ , closeCall )
11201120 b .ob .constructProjectForScope (closeCon .s , closeScope )
1121- b .appendBodyStmtFromScope (& closeCon , closeScope , "" /* stmtTag */ )
1121+ b .appendBodyStmtFromScope (& closeCon , closeScope , nil /* stmt */ )
11221122 b .appendPlpgSQLStmts (& closeCon , stmts [i + 1 :])
11231123 return b .callContinuation (& closeCon , s )
11241124
@@ -1142,7 +1142,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
11421142 fetchCon .def .Volatility = volatility .Volatile
11431143 fetchScope := b .buildFetch (fetchCon .s , t )
11441144 if t .IsMove {
1145- b .appendBodyStmtFromScope (& fetchCon , fetchScope , "" /* stmtTag */ )
1145+ b .appendBodyStmtFromScope (& fetchCon , fetchScope , nil /* stmt */ )
11461146 b .appendPlpgSQLStmts (& fetchCon , stmts [i + 1 :])
11471147 return b .callContinuation (& fetchCon , s )
11481148 }
@@ -1173,7 +1173,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
11731173 intoScope = b .callContinuation (& retCon , intoScope )
11741174
11751175 // Add the built statement to the FETCH continuation.
1176- b .appendBodyStmtFromScope (& fetchCon , intoScope , "" /* stmtTag */ )
1176+ b .appendBodyStmtFromScope (& fetchCon , intoScope , nil /* stmt */ )
11771177 return b .callContinuation (& fetchCon , s )
11781178
11791179 case * ast.Null :
@@ -1275,7 +1275,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
12751275 if len (target ) == 0 {
12761276 // When there is no INTO target, build the nested procedure call into a
12771277 // body statement that is only executed for its side effects.
1278- b .appendBodyStmtFromScope (& callCon , callScope , "" /* stmtTag */ )
1278+ b .appendBodyStmtFromScope (& callCon , callScope , nil /* stmt */ )
12791279 b .appendPlpgSQLStmts (& callCon , stmts [i + 1 :])
12801280 return b .callContinuation (& callCon , s )
12811281 }
@@ -1290,7 +1290,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
12901290 intoScope = b .callContinuation (& retCon , intoScope )
12911291
12921292 // Add the built statement to the CALL continuation.
1293- b .appendBodyStmtFromScope (& callCon , intoScope , "" /* stmtTag */ )
1293+ b .appendBodyStmtFromScope (& callCon , intoScope , nil /* stmt */ )
12941294 return b .callContinuation (& callCon , s )
12951295
12961296 case * ast.DoBlock :
@@ -1306,7 +1306,7 @@ func (b *plpgsqlBuilder) buildPLpgSQLStatements(stmts []ast.Statement, s *scope)
13061306 doCon := b .makeContinuation ("_stmt_do" )
13071307 doCon .def .Volatility = volatility .Volatile
13081308 bodyScope := b .ob .buildPLpgSQLDoBody (t )
1309- b .appendBodyStmtFromScope (& doCon , bodyScope , "" /* stmtTag */ )
1309+ b .appendBodyStmtFromScope (& doCon , bodyScope , nil /* stmt */ )
13101310 b .appendPlpgSQLStmts (& doCon , stmts [i + 1 :])
13111311 return b .callContinuation (& doCon , s )
13121312
@@ -1456,7 +1456,7 @@ func (b *plpgsqlBuilder) handleIntForLoop(
14561456 )
14571457 // Call recursively into the loop body continuation.
14581458 incScope = b .callContinuation (& loopCon , incScope )
1459- b .appendBodyStmtFromScope (& incrementCon , incScope , "" /* stmtTag */ )
1459+ b .appendBodyStmtFromScope (& incrementCon , incScope , nil /* stmt */ )
14601460
14611461 // Notably, we call the loop body continuation here, rather than the
14621462 // increment continuation, because the counter should not be incremented
@@ -2020,7 +2020,7 @@ func (b *plpgsqlBuilder) buildEndOfFunctionRaise(con *continuation) {
20202020 pgcode .RoutineExceptionFunctionExecutedNoReturnStatement .String (), /* code */
20212021 )
20222022 con .def .Volatility = volatility .Volatile
2023- b .appendBodyStmtFromScope (con , b .buildPLpgSQLRaise (con .s , args ), "" /* stmtTag */ )
2023+ b .appendBodyStmtFromScope (con , b .buildPLpgSQLRaise (con .s , args ), nil /* stmt */ )
20242024
20252025 // Build a dummy statement that returns NULL. It won't be executed, but
20262026 // ensures that the continuation routine's return type is correct.
@@ -2029,7 +2029,7 @@ func (b *plpgsqlBuilder) buildEndOfFunctionRaise(con *continuation) {
20292029 typedNull := b .ob .factory .ConstructNull (b .returnType )
20302030 b .ob .synthesizeColumn (eofScope , eofColName , b .returnType , nil /* expr */ , typedNull )
20312031 b .ob .constructProjectForScope (con .s , eofScope )
2032- b .appendBodyStmtFromScope (con , eofScope , "" /* stmtTag */ )
2032+ b .appendBodyStmtFromScope (con , eofScope , nil /* stmt */ )
20332033}
20342034
20352035// addOneRowCheck handles INTO STRICT, where a SQL statement is required to
@@ -2280,7 +2280,7 @@ func (b *plpgsqlBuilder) makeContinuationWithTyp(
22802280// routine definitions, which need to push the continuation before it is
22812281// finished. The separation also allows for appending multiple body statements.
22822282func (b * plpgsqlBuilder ) appendBodyStmtFromScope (
2283- con * continuation , bodyScope * scope , stmtTag string ,
2283+ con * continuation , bodyScope * scope , stmt tree. Statement ,
22842284) {
22852285 // Set the volatility of the continuation routine to the least restrictive
22862286 // volatility level in the Relational properties of the body statements.
@@ -2290,8 +2290,11 @@ func (b *plpgsqlBuilder) appendBodyStmtFromScope(
22902290 con .def .Volatility = vol
22912291 }
22922292 con .def .Body = append (con .def .Body , bodyExpr )
2293- con .def .BodyTags = append (con .def .BodyTags , stmtTag )
22942293 con .def .BodyProps = append (con .def .BodyProps , bodyScope .makePhysicalProps ())
2294+ if stmt != nil {
2295+ con .def .BodyTags = append (con .def .BodyTags , stmt .StatementTag ())
2296+ con .def .BodyASTs = append (con .def .BodyASTs , stmt )
2297+ }
22952298}
22962299
22972300// appendPlpgSQLStmts builds the given PLpgSQL statements into a relational
@@ -2301,7 +2304,7 @@ func (b *plpgsqlBuilder) appendPlpgSQLStmts(con *continuation, stmts []ast.State
23012304 // Make sure to push s before constructing the continuation scope to ensure
23022305 // that the parameter columns are not projected.
23032306 continuationScope := b .buildPLpgSQLStatements (stmts , con .s .push ())
2304- b .appendBodyStmtFromScope (con , continuationScope , "" /* stmtTag */ )
2307+ b .appendBodyStmtFromScope (con , continuationScope , nil /* stmt */ )
23052308}
23062309
23072310// callContinuation adds a column that projects the result of calling the
0 commit comments