Skip to content

Commit 3e2e58b

Browse files
committed
New routine _getObjectDescription() failed to cope with some aspects of
pre-7.3 pg_dump archive files: namespace isn't there, and in some cases te->tag may already be quotified. Per report from Alan Pevec and followup testing.
1 parent 112654c commit 3e2e58b

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.101 2005/01/11 05:14:10 tgl Exp $
18+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.102 2005/01/23 00:03:54 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -47,7 +47,8 @@ static char *modulename = gettext_noop("archiver");
4747

4848
static ArchiveHandle *_allocAH(const char *FileSpec, const ArchiveFormat fmt,
4949
const int compression, ArchiveMode mode);
50-
static void _getObjectDescription(PQExpBuffer buf, TocEntry *te);
50+
static void _getObjectDescription(PQExpBuffer buf, TocEntry *te,
51+
ArchiveHandle *AH);
5152
static void _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData, bool acl_pass);
5253

5354

@@ -2373,7 +2374,7 @@ _selectTablespace(ArchiveHandle *AH, const char *tablespace)
23732374
* information used is all that's available in older dump files.
23742375
*/
23752376
static void
2376-
_getObjectDescription(PQExpBuffer buf, TocEntry *te)
2377+
_getObjectDescription(PQExpBuffer buf, TocEntry *te, ArchiveHandle *AH)
23772378
{
23782379
const char *type = te->desc;
23792380

@@ -2393,8 +2394,22 @@ _getObjectDescription(PQExpBuffer buf, TocEntry *te)
23932394
strcmp(type, "TABLE") == 0 ||
23942395
strcmp(type, "TYPE") == 0)
23952396
{
2396-
appendPQExpBuffer(buf, "%s %s", type, fmtId(te->namespace));
2397-
appendPQExpBuffer(buf, ".%s", fmtId(te->tag));
2397+
appendPQExpBuffer(buf, "%s ", type);
2398+
if (te->namespace && te->namespace[0]) /* is null pre-7.3 */
2399+
appendPQExpBuffer(buf, "%s.", fmtId(te->namespace));
2400+
/*
2401+
* Pre-7.3 pg_dump would sometimes (not always) put
2402+
* a fmtId'd name into te->tag for an index.
2403+
* This check is heuristic, so make its scope as
2404+
* narrow as possible.
2405+
*/
2406+
if (AH->version < K_VERS_1_7 &&
2407+
te->tag[0] == '"' &&
2408+
te->tag[strlen(te->tag)-1] == '"' &&
2409+
strcmp(type, "INDEX") == 0)
2410+
appendPQExpBuffer(buf, "%s", te->tag);
2411+
else
2412+
appendPQExpBuffer(buf, "%s", fmtId(te->tag));
23982413
return;
23992414
}
24002415

@@ -2553,7 +2568,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
25532568
PQExpBuffer temp = createPQExpBuffer();
25542569

25552570
appendPQExpBuffer(temp, "ALTER ");
2556-
_getObjectDescription(temp, te);
2571+
_getObjectDescription(temp, te, AH);
25572572
appendPQExpBuffer(temp, " OWNER TO %s;", fmtId(te->owner));
25582573
ahprintf(AH, "%s\n\n", temp->data);
25592574
destroyPQExpBuffer(temp);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy