diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index bcd8eb3538..a853bce096 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1238,6 +1238,8 @@ exec_command_ef_ev(PsqlScanState scan_state, bool active_branch,
 			else
 				status = PSQL_CMD_NEWEDIT;
 		}
+		else
+			resetPQExpBuffer(query_buf);
 
 		free(obj_desc);
 	}
