Skip to content

Commit 150ffb2

Browse files
author
Hiroshi Inoue
committed
Adjust lo type in contrib during pg_restore so that pg_restore could
reload the type.
1 parent 7e4d435 commit 150ffb2

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.63 2002/11/23 03:59:08 momjian Exp $
18+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.64 2003/01/03 18:05:02 inoue Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -122,6 +122,85 @@ CloseArchive(Archive *AHX)
122122
die_horribly(AH, modulename, "could not close the output file in CloseArchive\n");
123123
}
124124

125+
/*
126+
* Adjust lo type in contrib for 7.3 or later.
127+
* There must be a cast between lo and oid.
128+
*/
129+
static void
130+
Adjust_lo_type(ArchiveHandle *AH)
131+
{
132+
PGresult *res;
133+
134+
/*
135+
* The cast function lo(oid) should be immutable.
136+
* If it's volatile it should be changed to
137+
* be immutable and the cast (oid as lo)
138+
* should be created.
139+
*/
140+
res = PQexec(AH->blobConnection, "begin;"
141+
"update pg_proc set provolatile = 'i'"
142+
" where proname = 'lo'"
143+
" and pronargs = 1"
144+
" and provolatile = 'v'"
145+
" and prorettype in (select oid from pg_type where typname = 'lo')"
146+
" and proargtypes[0] in (select oid from pg_type where typname = 'oid')");
147+
148+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
149+
die_horribly(AH, modulename, "could not adjust lo(oid) function");
150+
if (strcmp(PQcmdTuples(res), "1") == 0)
151+
{
152+
PQclear(res);
153+
/* create cast */
154+
res = PQexec(AH->blobConnection, "create cast"
155+
" (oid as lo) with function lo(oid) as implicit;commit");
156+
if (!res)
157+
die_horribly(AH, modulename, "couldn't create cast (oid as lo)");
158+
}
159+
else
160+
{
161+
PQclear(res);
162+
/* The change is needless */
163+
res = PQexec(AH->blobConnection, "rollback");
164+
if (!res)
165+
die_horribly(AH, modulename, "rollback error");
166+
}
167+
PQclear(res);
168+
169+
/*
170+
* The cast function oid(lo) should be immutable.
171+
* If it's volatile it should be changed to
172+
* be immutable and the cast (lo as oid)
173+
* should be created.
174+
*/
175+
res = PQexec(AH->blobConnection, "begin;"
176+
"update pg_proc set provolatile = 'i'"
177+
" where proname = 'oid'"
178+
" and provolatile = 'v'"
179+
" and pronargs = 1"
180+
" and prorettype in (select oid from pg_type where typname = 'oid')"
181+
" and proargtypes[0] in (select oid from pg_type where typname = 'lo')");
182+
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
183+
die_horribly(AH, modulename, "could not adjust oid(lo) function");
184+
if (strcmp(PQcmdTuples(res), "1") == 0)
185+
{
186+
PQclear(res);
187+
/* create cast */
188+
res = PQexec(AH->blobConnection, "create cast"
189+
" (lo as oid) with function oid(lo) as implicit;commit");
190+
if (!res)
191+
die_horribly(AH, modulename, "couldn't create cast (lo as oid)");
192+
}
193+
else
194+
{
195+
PQclear(res);
196+
/* the change is needless */
197+
res = PQexec(AH->blobConnection, "rollback");
198+
if (!res)
199+
die_horribly(AH, modulename, "rollback error");
200+
}
201+
PQclear(res);
202+
}
203+
125204
/* Public */
126205
void
127206
RestoreArchive(Archive *AHX, RestoreOptions *ropt)
@@ -357,6 +436,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
357436
/* NULL parameter means disable ALL user triggers */
358437
_disableTriggersIfNecessary(AH, NULL, ropt);
359438

439+
Adjust_lo_type(AH);
360440
te = AH->toc->next;
361441
while (te != AH->toc)
362442
{

0 commit comments

Comments
 (0)