diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c index c3beacdec1..a032284dbc 100644 --- a/src/bin/pg_dump/pg_restore.c +++ b/src/bin/pg_dump/pg_restore.c @@ -315,6 +315,13 @@ main(int argc, char **argv) exit_nicely(1); } + /* Complain if the input file is used as the output file */ + if (opts->filename && inputFileSpec) + { + if (strcmp(opts->filename, "-") != 0 && strcmp(opts->filename, inputFileSpec) == 0) + pg_fatal("input file and output file cannot be the same"); + } + /* Complain if neither -f nor -d was specified (except if dumping TOC) */ if (!opts->cparams.dbname && !opts->filename && !opts->tocSummary) pg_fatal("one of -d/--dbname and -f/--file must be specified");