1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-23 14:01:44 +03:00

Cleaner solution to the problem of loading pre-7.3 dumps containing

columns of type lo (see contrib/lo).  Rather than hacking the function
definitions on-the-fly, just modify the queries issued by FixupBlobRefs
so that they work even if CREATE CAST hasn't been issued.
This commit is contained in:
Tom Lane
2003-02-01 22:06:59 +00:00
parent 330b4e4215
commit e0a1ee2053
2 changed files with 41 additions and 109 deletions

View File

@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.66 2003/01/27 00:23:38 tgl Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.67 2003/02/01 22:06:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -122,102 +122,6 @@ CloseArchive(Archive *AHX)
die_horribly(AH, modulename, "could not close the output file in CloseArchive\n");
}
/*
* This function repairs a slip when upgrading PG cast
* mechanism from 7.2 or earlier to 7.3 or later.
* The casts between lo and oid are needed when retrieving
* lo type data in FixupBlobRefs and so adjust lo type in
* contrib before processing FixupBlobRefs.
*/
static void
Adjust_lo_type(ArchiveHandle *AH)
{
PGresult *res;
int nTuples;
/*
* First check the existence of the cast oid as lo.
*/
res = PQexec(AH->blobConnection, "select 1 from pg_cast where"
" castsource in (select oid from pg_type where typname = 'oid')"
" and casttarget in (select oid from pg_type where typname = 'lo')");
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
die_horribly(AH, modulename, "error while checking the cast oid as lo\n");
nTuples = PQntuples(res);
PQclear(res);
if (nTuples == 0)
{
/*
* Check the existence of the cast function lo(oid)
* and change it to be IMMUTABLE.
*/
res = PQexec(AH->blobConnection, "update pg_proc set provolatile = 'i'"
" where proname = 'lo'"
" and pronargs = 1"
" and prorettype in (select oid from pg_type where typname = 'lo')"
" and proargtypes[0] in (select oid from pg_type where typname = 'oid')");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
die_horribly(AH, modulename, "could not adjust lo(oid) function\n");
nTuples = atoi(PQcmdTuples(res));
PQclear(res);
if (nTuples == 1)
{
/*
* The cast function lo(oid) exists and
* then create the correspoding cast.
*/
res = PQexec(AH->blobConnection, "create cast"
" (oid as lo) with function lo(oid) as implicit");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
die_horribly(AH, modulename, "couldn't create cast (oid as lo)\n");
PQclear(res);
}
}
/*
* Also check the existence of the cast lo as oid.
*/
res = PQexec(AH->blobConnection, "select 1 from pg_cast where"
" castsource in (select oid from pg_type where typname = 'lo')"
" and casttarget in (select oid from pg_type where typname = 'oid')");
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
die_horribly(AH, modulename, "error while checking the cast lo as oid\n");
nTuples = PQntuples(res);
PQclear(res);
if (nTuples == 0)
{
/*
* Check the existence of the cast function oid(lo)
* and change it to be IMMUTABLE.
*/
res = PQexec(AH->blobConnection, "update pg_proc set provolatile = 'i'"
" where proname = 'oid'"
" and pronargs = 1"
" and prorettype in (select oid from pg_type where typname = 'oid')"
" and proargtypes[0] in (select oid from pg_type where typname = 'lo')");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
die_horribly(AH, modulename, "could not adjust oid(lo) function\n");
nTuples = atoi(PQcmdTuples(res));
PQclear(res);
if (nTuples == 1)
{
/*
* The cast function oid(lo) exists and
* then create the correspoding cast.
*/
res = PQexec(AH->blobConnection, "create cast"
" (lo as oid) with function oid(lo) as implicit");
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
die_horribly(AH, modulename, "couldn't create cast (lo as oid)\n");
PQclear(res);
}
}
}
/* Public */
void
RestoreArchive(Archive *AHX, RestoreOptions *ropt)
@ -453,7 +357,6 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
/* NULL parameter means disable ALL user triggers */
_disableTriggersIfNecessary(AH, NULL, ropt);
Adjust_lo_type(AH);
te = AH->toc->next;
while (te != AH->toc)
{