Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit006f42c

Browse files
committed
Fix a couple of issues with pg_dump's handling of inheritance child tables
that have default expressions different from their parent. First, if theparent table's default expression has to be split out as a separateALTER TABLE command, we need a dependency constraint to ensure that thechild's command is given second. This is because the ALTER TABLE on theparent will propagate to the child. (We can't prevent that by using ONLY onthe parent's command, since it's possible that other children exist thatshould receive the inherited default.) Second, if the child has a NULLdefault where the parent does not, we have to explicitly say DEFAULT NULL onthe child in order for this state to be preserved after reload. (The latteractually doesn't work right because of a backend bug, but that is a separateissue.)Backpatch as far as 8.0. 7.x pg_dump has enough issues with altered tables(due to lack of dependency analysis) that trying to fix this one doesn't seemvery productive.
1 parent73e6f9d commit006f42c

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.98 2007/09/23 23:39:36 tgl Exp $
14+
* $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.99 2007/10/28 19:08:02 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -326,19 +326,53 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
326326

327327
if (inhAttrInd!=-1)
328328
{
329+
AttrDefInfo*inhDef=parent->attrdefs[inhAttrInd];
330+
329331
foundAttr= true;
330332
foundNotNull |=parent->notnull[inhAttrInd];
331-
if (attrDef!=NULL)/* If we have a default, check
332-
* parent */
333+
if (inhDef!=NULL)
333334
{
334-
AttrDefInfo*inhDef;
335+
defaultsFound= true;
336+
/*
337+
* If any parent has a default and the child doesn't,
338+
* we have to emit an explicit DEFAULT NULL clause
339+
* for the child, else the parent's default will win.
340+
*/
341+
if (attrDef==NULL)
342+
{
343+
attrDef= (AttrDefInfo*)malloc(sizeof(AttrDefInfo));
344+
attrDef->dobj.objType=DO_ATTRDEF;
345+
attrDef->dobj.catId.tableoid=0;
346+
attrDef->dobj.catId.oid=0;
347+
AssignDumpId(&attrDef->dobj);
348+
attrDef->adtable=tbinfo;
349+
attrDef->adnum=j+1;
350+
attrDef->adef_expr=strdup("NULL");
351+
352+
attrDef->dobj.name=strdup(tbinfo->dobj.name);
353+
attrDef->dobj.namespace=tbinfo->dobj.namespace;
335354

336-
inhDef=parent->attrdefs[inhAttrInd];
337-
if (inhDef!=NULL)
355+
attrDef->dobj.dump=tbinfo->dobj.dump;
356+
357+
attrDef->separate= false;
358+
addObjectDependency(&tbinfo->dobj,
359+
attrDef->dobj.dumpId);
360+
361+
tbinfo->attrdefs[j]=attrDef;
362+
}
363+
if (strcmp(attrDef->adef_expr,inhDef->adef_expr)!=0)
338364
{
339-
defaultsFound= true;
340-
defaultsMatch &= (strcmp(attrDef->adef_expr,
341-
inhDef->adef_expr)==0);
365+
defaultsMatch= false;
366+
/*
367+
* Whenever there is a non-matching parent
368+
* default, add a dependency to force the parent
369+
* default to be dumped first, in case the
370+
* defaults end up being dumped as separate
371+
* commands. Otherwise the parent default will
372+
* override the child's when it is applied.
373+
*/
374+
addObjectDependency(&attrDef->dobj,
375+
inhDef->dobj.dumpId);
342376
}
343377
}
344378
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp