On 2023-09-19 12:53, Michael Paquier wrote:
Adding a comment looks important to me once we consider the edit as a
path that can fail and the edited query is only executed then reset
when we have PSQL_CMD_NEWEDIT as status. I would suggest the patch
attached instead, taking care of the error case of this thread and the
ones I've spotted.
Thank you everyone for the reviews. I fixed the patch for the error and
also added a comment
. You can see attached file.
Ryoga Yoshida
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index bcd8eb3538..eb306d8d77 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -1239,6 +1239,15 @@ exec_command_ef_ev(PsqlScanState scan_state, bool active_branch,
status = PSQL_CMD_NEWEDIT;
}
+ if (status == PSQL_CMD_ERROR)
+ {
+ /*
+ * clear the query buffer because it could be overwritten with
+ * an incomplete query string due to certain failures.
+ */
+ resetPQExpBuffer(query_buf);
+ }
+
free(obj_desc);
}
else