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)
ahprintf(AH, "%s", te->dropStmt);
}
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 *mark;
......@@ -447,8 +461,8 @@ RestoreArchive(Archive *AHX)
PQExpBuffer ftStmt = createPQExpBuffer();
/*
* Need to inject IF EXISTS clause after ALTER TABLE
* part in ALTER TABLE .. DROP statement
* Need to inject IF EXISTS clause after ALTER
* TABLE part in ALTER TABLE .. DROP statement
*/
if (strncmp(dropStmt, "ALTER TABLE", 11) == 0)
{
......@@ -458,15 +472,15 @@ RestoreArchive(Archive *AHX)
}
/*
* ALTER TABLE..ALTER COLUMN..DROP DEFAULT does not
* support the IF EXISTS clause, and therefore we
* simply emit the original command for such objects.
* For other objects, we need to extract the first
* part of the DROP which includes the object type.
* Most of the time this matches te->desc, so search
* for that; however for the different kinds of
* CONSTRAINTs, we know to search for hardcoded "DROP
* CONSTRAINT" instead.
* ALTER TABLE..ALTER COLUMN..DROP DEFAULT does
* not support the IF EXISTS clause, and therefore
* we simply emit the original command for such
* objects. For other objects, we need to extract
* the first part of the DROP which includes the
* object type. Most of the time this matches
* te->desc, so search for that; however for the
* different kinds of CONSTRAINTs, we know to
* search for hardcoded "DROP CONSTRAINT" instead.
*/
if (strcmp(te->desc, "DEFAULT") == 0)
appendPQExpBuffer(ftStmt, "%s", dropStmt);
......@@ -498,6 +512,7 @@ RestoreArchive(Archive *AHX)
}
}
}
}
/*
* _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