diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index bcd8eb35387..4dfcf04fe03 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1127,6 +1127,14 @@ exec_command_edit(PsqlScanState scan_state, bool active_branch, else status = PSQL_CMD_ERROR; } + + /* + * On error while editing or if specifying an incorrect line + * number, reset the query buffer. + */ + if (status == PSQL_CMD_ERROR) + resetPQExpBuffer(query_buf); + free(fname); free(ln); } @@ -1239,6 +1247,13 @@ exec_command_ef_ev(PsqlScanState scan_state, bool active_branch, status = PSQL_CMD_NEWEDIT; } + /* + * On error while doing object lookup or while editing, or if + * specifying an incorrect line number, reset the query buffer. + */ + if (status == PSQL_CMD_ERROR) + resetPQExpBuffer(query_buf); + free(obj_desc); } else