|
11 | 11 | *
|
12 | 12 | *
|
13 | 13 | * 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 $ |
15 | 15 | *
|
16 | 16 | *-------------------------------------------------------------------------
|
17 | 17 | */
|
@@ -326,19 +326,53 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
|
326 | 326 |
|
327 | 327 | if (inhAttrInd != -1)
|
328 | 328 | {
|
| 329 | + AttrDefInfo *inhDef = parent->attrdefs[inhAttrInd]; |
| 330 | + |
329 | 331 | foundAttr = true;
|
330 | 332 | foundNotNull |= parent->notnull[inhAttrInd];
|
331 |
| - if (attrDef != NULL) /* If we have a default, check |
332 |
| - * parent */ |
| 333 | + if (inhDef != NULL) |
333 | 334 | {
|
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; |
335 | 354 |
|
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) |
338 | 364 | {
|
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); |
342 | 376 | }
|
343 | 377 | }
|
344 | 378 | }
|
|
0 commit comments