diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2020-03-20 16:04:15 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2020-03-20 16:04:15 +0100 |
commit | b03436994bcc4909dd644fd5ae6d9a9acdf30da5 (patch) | |
tree | 20babd81d95f96458caa3baa081b4322a8a2fe0a /src | |
parent | 85f6b49c2c53fb1e08d918ec9305faac13cf7ad6 (diff) | |
download | postgresql-b03436994bcc4909dd644fd5ae6d9a9acdf30da5.tar.gz postgresql-b03436994bcc4909dd644fd5ae6d9a9acdf30da5.zip |
psql: Catch and report errors while printing result table
Errors (for example I/O errors or disk full) while printing out result
tables were completely ignored, which could result in silently
truncated output in scripts, for example. Fix by adding some basic
error checking and reporting.
Author: Daniel Verite <daniel@manitou-mail.org>
Author: David Zhang <david.zhang@highgo.ca>
Discussion: https://www.postgresql.org/message-id/flat/9a0b3c8d-ee14-4b1d-9d0a-2c993bdabacc@manitou-mail.org
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/psql/common.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 67df0cd2c77..396a40089ce 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -708,6 +708,7 @@ static bool PrintQueryTuples(const PGresult *results) { printQueryOpt my_popt = pset.popt; + bool result = true; /* one-shot expanded output requested via \gx */ if (pset.g_expanded) @@ -725,6 +726,11 @@ PrintQueryTuples(const PGresult *results) disable_sigpipe_trap(); printQuery(results, &my_popt, fout, false, pset.logfile); + if (ferror(fout)) + { + pg_log_error("could not print result table: %m"); + result = false; + } if (is_pipe) { @@ -735,9 +741,16 @@ PrintQueryTuples(const PGresult *results) fclose(fout); } else + { printQuery(results, &my_popt, pset.queryFout, false, pset.logfile); + if (ferror(pset.queryFout)) + { + pg_log_error("could not print result table: %m"); + result = false; + } + } - return true; + return result; } |