mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
Fix pg_dump's --if-exists for large objects
This was born broken in 9067310cc5dd590e36c2c3219dbf3961d7c9f8cb. Per trouble report from Joachim Wieland. Pavel Stěhule and Álvaro Herrera
This commit is contained in:
parent
6f1310024d
commit
5f4f66f671
@ -427,6 +427,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;
|
||||
@ -435,8 +449,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)
|
||||
{
|
||||
@ -446,15 +460,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);
|
||||
@ -486,6 +500,7 @@ RestoreArchive(Archive *AHX)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* _selectOutputSchema may have set currSchema to reflect the effect
|
||||
|
Loading…
x
Reference in New Issue
Block a user