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
4848static ArchiveHandle * _allocAH (const char * FileSpec ,const ArchiveFormat fmt ,
4949const int compression ,ArchiveMode mode );
50- static void _getObjectDescription (PQExpBuffer buf ,TocEntry * te );
50+ static void _getObjectDescription (PQExpBuffer buf ,TocEntry * te ,
51+ ArchiveHandle * AH );
5152static 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 */
23752376static void
2376- _getObjectDescription (PQExpBuffer buf ,TocEntry * te )
2377+ _getObjectDescription (PQExpBuffer buf ,TocEntry * te , ArchiveHandle * AH )
23772378{
23782379const char * type = te -> desc ;
23792380
@@ -2393,8 +2394,22 @@ _getObjectDescription(PQExpBuffer buf, TocEntry *te)
23932394strcmp (type ,"TABLE" )== 0 ||
23942395strcmp (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 ));
23982413return ;
23992414}
24002415
@@ -2553,7 +2568,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
25532568PQExpBuffer temp = createPQExpBuffer ();
25542569
25552570appendPQExpBuffer (temp ,"ALTER " );
2556- _getObjectDescription (temp ,te );
2571+ _getObjectDescription (temp ,te , AH );
25572572appendPQExpBuffer (temp ," OWNER TO %s;" ,fmtId (te -> owner ));
25582573ahprintf (AH ,"%s\n\n" ,temp -> data );
25592574destroyPQExpBuffer (temp );