</varlistentry>
+ <varlistentry>
+ <term><literal>\errverbose</literal></term>
+
+ <listitem>
+ <para>
+ Repeats the most recent server error message at maximum
+ verbosity, as though <varname>VERBOSITY</varname> were set
+ to <literal>verbose</> and <varname>SHOW_CONTEXT</varname> were
+ set to <literal>always</>.
+ </para>
+ </listitem>
+ </varlistentry>
+
+
<varlistentry>
<term><literal>\f [ <replaceable class="parameter">string</replaceable> ]</literal></term>
that context will be shown in error messages, but not in notice or
warning messages). This setting has no effect
when <varname>VERBOSITY</> is set to <literal>terse</>.
+ (See also <command>\errverbose</>, for use when you want a verbose
+ version of the error you just got.)
</para>
</listitem>
</varlistentry>
This variable can be set to the values <literal>default</>,
<literal>verbose</>, or <literal>terse</> to control the verbosity
of error reports.
+ (See also <command>\errverbose</>, for use when you want a verbose
+ version of the error you just got.)
</para>
</listitem>
</varlistentry>
}
}
+ /* \errverbose -- display verbose message from last failed query */
+ else if (strcmp(cmd, "errverbose") == 0)
+ {
+ if (pset.last_error_result)
+ {
+ char *msg;
+
+ msg = PQresultVerboseErrorMessage(pset.last_error_result,
+ PQERRORS_VERBOSE,
+ PQSHOW_CONTEXT_ALWAYS);
+ if (msg)
+ {
+ psql_error("%s", msg);
+ PQfreemem(msg);
+ }
+ else
+ puts(_("out of memory"));
+ }
+ else
+ puts(_("There was no previous error."));
+ }
+
/* \f -- change field separator */
else if (strcmp(cmd, "f") == 0)
{
}
+/*
+ * ClearOrSaveResult
+ *
+ * If the result represents an error, remember it for possible display by
+ * \errverbose. Otherwise, just PQclear() it.
+ */
+static void
+ClearOrSaveResult(PGresult *result)
+{
+ if (result)
+ {
+ switch (PQresultStatus(result))
+ {
+ case PGRES_NONFATAL_ERROR:
+ case PGRES_FATAL_ERROR:
+ if (pset.last_error_result)
+ PQclear(pset.last_error_result);
+ pset.last_error_result = result;
+ break;
+
+ default:
+ PQclear(result);
+ break;
+ }
+ }
+}
+
/*
* PSQLexec
if (!AcceptResult(res))
{
- PQclear(res);
+ ClearOrSaveResult(res);
res = NULL;
}
if (!AcceptResult(res))
{
- PQclear(res);
+ ClearOrSaveResult(res);
return 0;
}
if (PQresultStatus(results) != PGRES_COMMAND_OK)
{
psql_error("%s", PQerrorMessage(pset.db));
- PQclear(results);
+ ClearOrSaveResult(results);
ResetCancelConn();
goto sendquery_cleanup;
}
- PQclear(results);
+ ClearOrSaveResult(results);
transaction_status = PQtransactionStatus(pset.db);
}
if (PQresultStatus(results) != PGRES_COMMAND_OK)
{
psql_error("%s", PQerrorMessage(pset.db));
- PQclear(results);
+ ClearOrSaveResult(results);
ResetCancelConn();
goto sendquery_cleanup;
}
- PQclear(results);
+ ClearOrSaveResult(results);
on_error_rollback_savepoint = true;
}
}
if (PQresultStatus(svptres) != PGRES_COMMAND_OK)
{
psql_error("%s", PQerrorMessage(pset.db));
- PQclear(svptres);
+ ClearOrSaveResult(svptres);
OK = false;
PQclear(results);
}
}
- PQclear(results);
+ ClearOrSaveResult(results);
/* Possible microtiming output */
if (pset.timing)
results = PQexec(pset.db, "BEGIN");
OK = AcceptResult(results) &&
(PQresultStatus(results) == PGRES_COMMAND_OK);
- PQclear(results);
+ ClearOrSaveResult(results);
if (!OK)
return false;
started_txn = true;
results = PQexec(pset.db, buf.data);
OK = AcceptResult(results) &&
(PQresultStatus(results) == PGRES_COMMAND_OK);
- PQclear(results);
+ ClearOrSaveResult(results);
termPQExpBuffer(&buf);
if (!OK)
goto cleanup;
OK = AcceptResult(results);
Assert(!OK);
- PQclear(results);
+ ClearOrSaveResult(results);
break;
}
{
/* StoreQueryTuple will complain if not exactly one row */
OK = StoreQueryTuple(results);
- PQclear(results);
+ ClearOrSaveResult(results);
break;
}
printQuery(results, &my_popt, fout, is_pager, pset.logfile);
- PQclear(results);
+ ClearOrSaveResult(results);
/* after the first result set, disallow header decoration */
my_popt.topt.start_table = false;
OK = AcceptResult(results) &&
(PQresultStatus(results) == PGRES_COMMAND_OK);
}
- PQclear(results);
+ ClearOrSaveResult(results);
if (started_txn)
{
results = PQexec(pset.db, OK ? "COMMIT" : "ROLLBACK");
OK &= AcceptResult(results) &&
(PQresultStatus(results) == PGRES_COMMAND_OK);
- PQclear(results);
+ ClearOrSaveResult(results);
}
if (pset.timing)
* Use "psql --help=commands | wc" to count correctly. It's okay to count
* the USE_READLINE line even in builds without that.
*/
- output = PageOutput(109, pager ? &(pset.popt.topt) : NULL);
+ output = PageOutput(110, pager ? &(pset.popt.topt) : NULL);
fprintf(output, _("General\n"));
fprintf(output, _(" \\copyright show PostgreSQL usage and distribution terms\n"));
+ fprintf(output, _(" \\errverbose show most recent error message at maximum verbosity\n"));
fprintf(output, _(" \\g [FILE] or ; execute query (and send results to file or |pipe)\n"));
fprintf(output, _(" \\gset [PREFIX] execute query and store results in psql variables\n"));
fprintf(output, _(" \\q quit psql\n"));
FILE *copyStream; /* Stream to read/write for \copy command */
+ PGresult *last_error_result; /* most recent error result, if any */
+
printQueryOpt popt;
char *gfname; /* one-shot file output argument for \g */
pset.queryFout = stdout;
pset.queryFoutPipe = false;
pset.copyStream = NULL;
+ pset.last_error_result = NULL;
pset.cur_cmd_source = stdin;
pset.cur_cmd_interactive = false;
"\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl", "\\dL",
"\\dm", "\\dn", "\\do", "\\dO", "\\dp", "\\drds", "\\ds", "\\dS",
"\\dt", "\\dT", "\\dv", "\\du", "\\dx", "\\dy",
- "\\e", "\\echo", "\\ef", "\\encoding", "\\ev",
+ "\\e", "\\echo", "\\ef", "\\encoding", "\\errverbose", "\\ev",
"\\f", "\\g", "\\gset", "\\h", "\\help", "\\H", "\\i", "\\ir", "\\l",
"\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink",
"\\o", "\\p", "\\password", "\\prompt", "\\pset", "\\q", "\\qecho", "\\r",