Commit fd02931a authored by Alvaro Herrera's avatar Alvaro Herrera

Fix pg_dump's --if-exists for large objects

This was born broken in 9067310c.

Per trouble report from Joachim Wieland.

Pavel Stěhule and Álvaro Herrera
parent 35419aeb
...@@ -439,6 +439,20 @@ RestoreArchive(Archive *AHX) ...@@ -439,6 +439,20 @@ RestoreArchive(Archive *AHX)
ahprintf(AH, "%s", te->dropStmt); ahprintf(AH, "%s", te->dropStmt);
} }
else else
{
/*
* Inject an appropriate spelling of "if exists". For
* large objects, we have a separate routine that
* knows how to do it, without depending on
* te->dropStmt; use that. For other objects we need
* to parse the command.
*
*/
if (strncmp(te->desc, "BLOB", 4) == 0)
{
DropBlobIfExists(AH, te->catalogId.oid);
}
else
{ {
char buffer[40]; char buffer[40];
char *mark; char *mark;
...@@ -447,8 +461,8 @@ RestoreArchive(Archive *AHX) ...@@ -447,8 +461,8 @@ RestoreArchive(Archive *AHX)
PQExpBuffer ftStmt = createPQExpBuffer(); PQExpBuffer ftStmt = createPQExpBuffer();
/* /*
* Need to inject IF EXISTS clause after ALTER TABLE * Need to inject IF EXISTS clause after ALTER
* part in ALTER TABLE .. DROP statement * TABLE part in ALTER TABLE .. DROP statement
*/ */
if (strncmp(dropStmt, "ALTER TABLE", 11) == 0) if (strncmp(dropStmt, "ALTER TABLE", 11) == 0)
{ {
...@@ -458,15 +472,15 @@ RestoreArchive(Archive *AHX) ...@@ -458,15 +472,15 @@ RestoreArchive(Archive *AHX)
} }
/* /*
* ALTER TABLE..ALTER COLUMN..DROP DEFAULT does not * ALTER TABLE..ALTER COLUMN..DROP DEFAULT does
* support the IF EXISTS clause, and therefore we * not support the IF EXISTS clause, and therefore
* simply emit the original command for such objects. * we simply emit the original command for such
* For other objects, we need to extract the first * objects. For other objects, we need to extract
* part of the DROP which includes the object type. * the first part of the DROP which includes the
* Most of the time this matches te->desc, so search * object type. Most of the time this matches
* for that; however for the different kinds of * te->desc, so search for that; however for the
* CONSTRAINTs, we know to search for hardcoded "DROP * different kinds of CONSTRAINTs, we know to
* CONSTRAINT" instead. * search for hardcoded "DROP CONSTRAINT" instead.
*/ */
if (strcmp(te->desc, "DEFAULT") == 0) if (strcmp(te->desc, "DEFAULT") == 0)
appendPQExpBuffer(ftStmt, "%s", dropStmt); appendPQExpBuffer(ftStmt, "%s", dropStmt);
...@@ -498,6 +512,7 @@ RestoreArchive(Archive *AHX) ...@@ -498,6 +512,7 @@ RestoreArchive(Archive *AHX)
} }
} }
} }
}
/* /*
* _selectOutputSchema may have set currSchema to reflect the effect * _selectOutputSchema may have set currSchema to reflect the effect
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment