aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-01-19 19:32:47 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-01-19 19:32:47 -0500
commit488e89bf725a3b4a1caf9e3e82ae6e75e914d123 (patch)
tree8159f01addf74a2ccae19aa88583485035c4b140
parentabe203304e1567c5938b348a8d9c5ad9b909742d (diff)
downloadpostgresql-488e89bf725a3b4a1caf9e3e82ae6e75e914d123.tar.gz
postgresql-488e89bf725a3b4a1caf9e3e82ae6e75e914d123.zip
Avoid harmless warning from pg_dump --if-exists mode.
If the public schema has a non-default owner (perhaps due to dropping and recreating it) then use of pg_dump's "--if-exists" option results in a warning message: warning: could not find where to insert IF EXISTS in statement "-- *not* dropping schema, since initdb creates it" This is harmless since the dump output is the same either way, but nonetheless it's undesirable. It's the fault of commit a7a7be1f2, which created situations where a TOC entry's "defn" or "dropStmt" fields could be just comments. Although that commit fixed up the kluges in pg_backup_archiver.c that munge defn strings, it missed doing so for the one that munges dropStmts. Per bug# 17753 from Justin Zhang. Discussion: https://postgr.es/m/17753-9c8773631747ee1c@postgresql.org
-rw-r--r--src/bin/pg_dump/pg_backup_archiver.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index 77fe51a3a53..eed28b2af89 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -529,9 +529,14 @@ RestoreArchive(Archive *AHX)
*/
if (*te->dropStmt != '\0')
{
- if (!ropt->if_exists)
+ if (!ropt->if_exists ||
+ strncmp(te->dropStmt, "--", 2) == 0)
{
- /* No --if-exists? Then just use the original */
+ /*
+ * Without --if-exists, or if it's just a comment (as
+ * happens for the public schema), print the dropStmt
+ * as-is.
+ */
ahprintf(AH, "%s", te->dropStmt);
}
else