aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2014-10-24 07:14:09 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2014-10-24 07:14:09 -0300
commit3c2aa0c6f27fc921c881b3bf0b6df03fdf557304 (patch)
treeef071cc4abb482ad2089861d4d42a86913688b43 /src
parentb01a4f68386f8bbc62c308138f23e436cb274629 (diff)
downloadpostgresql-3c2aa0c6f27fc921c881b3bf0b6df03fdf557304.tar.gz
postgresql-3c2aa0c6f27fc921c881b3bf0b6df03fdf557304.zip
psql: complain if pg_dump custom-format is detected
Apparently, this is a very common mistake for users to make; it is better to have it fail reasonably rather than throw potentially a large number of errors. Since we have a magic string at the start of the file, we can detect the case easily and there's no other possible useful behavior anyway. Author: Craig Ringer
Diffstat (limited to 'src')
-rw-r--r--src/bin/psql/mainloop.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c
index 98211dcb2a7..7b026097015 100644
--- a/src/bin/psql/mainloop.c
+++ b/src/bin/psql/mainloop.c
@@ -175,6 +175,18 @@ MainLoop(FILE *source)
if (pset.lineno == 1 && pset.encoding == PG_UTF8 && strncmp(line, "\xef\xbb\xbf", 3) == 0)
memmove(line, line + 3, strlen(line + 3) + 1);
+ /* Detect attempts to run custom-format dumps as SQL scripts */
+ if (pset.lineno == 1 && !pset.cur_cmd_interactive &&
+ strncmp(line, "PGDMP", 5) == 0)
+ {
+ free(line);
+ puts(_("The input is a PostgreSQL custom-format dump.\n"
+ "Use the pg_restore command-line client to restore this dump to a database.\n"));
+ fflush(stdout);
+ successResult = EXIT_FAILURE;
+ break;
+ }
+
/* nothing left on line? then ignore */
if (line[0] == '\0' && !psql_scan_in_quote(scan_state))
{