Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b034369

Browse files
committed
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
1 parent 85f6b49 commit b034369

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/bin/psql/common.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ static bool
708708
PrintQueryTuples(const PGresult *results)
709709
{
710710
printQueryOpt my_popt = pset.popt;
711+
bool result = true;
711712

712713
/* one-shot expanded output requested via \gx */
713714
if (pset.g_expanded)
@@ -725,6 +726,11 @@ PrintQueryTuples(const PGresult *results)
725726
disable_sigpipe_trap();
726727

727728
printQuery(results, &my_popt, fout, false, pset.logfile);
729+
if (ferror(fout))
730+
{
731+
pg_log_error("could not print result table: %m");
732+
result = false;
733+
}
728734

729735
if (is_pipe)
730736
{
@@ -735,9 +741,16 @@ PrintQueryTuples(const PGresult *results)
735741
fclose(fout);
736742
}
737743
else
744+
{
738745
printQuery(results, &my_popt, pset.queryFout, false, pset.logfile);
746+
if (ferror(pset.queryFout))
747+
{
748+
pg_log_error("could not print result table: %m");
749+
result = false;
750+
}
751+
}
739752

740-
return true;
753+
return result;
741754
}
742755

743756

0 commit comments

Comments
 (0)