Skip to content

Commit 803204b

Browse files
committed
Playing around with pg_dump for a while resulted in some
fixes, enhancements and some found bugs not yet fixed. After all I was able to get useful results when dumping/reloading the regression database. Jan
1 parent 57d57d9 commit 803204b

File tree

5 files changed

+365
-155
lines changed

5 files changed

+365
-155
lines changed

src/backend/rewrite/rewriteDefine.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.22 1998/10/02 16:27:46 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.23 1998/10/06 22:14:14 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -243,6 +243,7 @@ DefineQueryRewrite(RuleStmt *stmt)
243243
Form_pg_attribute attr;
244244
char *attname;
245245
int i;
246+
char expected_name[NAMEDATALEN + 5];
246247

247248
/*
248249
* So there cannot be INSTEAD NOTHING, ...
@@ -269,7 +270,7 @@ DefineQueryRewrite(RuleStmt *stmt)
269270

270271
/*
271272
* ... the targetlist of the SELECT action must
272-
* exactly match the event relation ...
273+
* exactly match the event relation, ...
273274
*/
274275
event_relation = heap_openr(event_obj->relname);
275276
if (event_relation == NULL)
@@ -295,8 +296,8 @@ DefineQueryRewrite(RuleStmt *stmt)
295296
}
296297

297298
/*
298-
* ... and final there must not be another ON SELECT
299-
* rule already.
299+
* ... there must not be another ON SELECT
300+
* rule already ...
300301
*/
301302
if (event_relation->rd_rules != NULL) {
302303
for (i = 0; i < event_relation->rd_rules->numLocks; i++) {
@@ -309,6 +310,15 @@ DefineQueryRewrite(RuleStmt *stmt)
309310
}
310311

311312
heap_close(event_relation);
313+
314+
/*
315+
* ... and finally the rule must be named _RETviewname.
316+
*/
317+
sprintf(expected_name, "_RET%s", event_obj->relname);
318+
if (strcmp(expected_name, stmt->rulename) != 0) {
319+
elog(ERROR, "view rule for %s must be named %s",
320+
event_obj->relname, expected_name);
321+
}
312322
}
313323

314324
/*

src/backend/utils/adt/ruleutils.c

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* out of it's tuple
44
*
55
* IDENTIFICATION
6-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.4 1998/10/02 16:27:51 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.5 1998/10/06 22:14:16 momjian Exp $
77
*
88
* This software is copyrighted by Jan Wieck - Hamburg.
99
*
@@ -415,7 +415,7 @@ pg_get_indexdef(Oid indexrelid)
415415
* Start the index definition
416416
* ----------
417417
*/
418-
sprintf(buf, "CREATE %sINDEX %s ON %s USING %s (",
418+
sprintf(buf, "CREATE %sINDEX \"%s\" ON \"%s\" USING %s (",
419419
idxrec->indisunique ? "UNIQUE " : "",
420420
nameout(&(idxrelrec->relname)),
421421
nameout(&(indrelrec->relname)),
@@ -439,11 +439,13 @@ pg_get_indexdef(Oid indexrelid)
439439
* Add the indexed field name
440440
* ----------
441441
*/
442+
strcat(keybuf, "\"");
442443
if (idxrec->indkey[keyno] == ObjectIdAttributeNumber - 1)
443444
strcat(keybuf, "oid");
444445
else
445446
strcat(keybuf, get_attribute_name(idxrec->indrelid,
446447
idxrec->indkey[keyno]));
448+
strcat(keybuf, "\"");
447449

448450
/* ----------
449451
* If not a functional index, add the operator class name
@@ -462,8 +464,9 @@ pg_get_indexdef(Oid indexrelid)
462464
spi_tup = SPI_tuptable->vals[0];
463465
spi_ttc = SPI_tuptable->tupdesc;
464466
spi_fno = SPI_fnumber(spi_ttc, "opcname");
465-
strcat(keybuf, " ");
467+
strcat(keybuf, " \"");
466468
strcat(keybuf, SPI_getvalue(spi_tup, spi_ttc, spi_fno));
469+
strcat(keybuf, "\"");
467470
}
468471
}
469472

@@ -482,8 +485,9 @@ pg_get_indexdef(Oid indexrelid)
482485
elog(ERROR, "cache lookup for proc %d failed", idxrec->indproc);
483486

484487
procStruct = (Form_pg_proc) GETSTRUCT(proctup);
488+
strcat(buf, "\"");
485489
strcat(buf, nameout(&(procStruct->proname)));
486-
strcat(buf, " (");
490+
strcat(buf, "\" (");
487491
strcat(buf, keybuf);
488492
strcat(buf, ") ");
489493

@@ -498,7 +502,9 @@ pg_get_indexdef(Oid indexrelid)
498502
spi_tup = SPI_tuptable->vals[0];
499503
spi_ttc = SPI_tuptable->tupdesc;
500504
spi_fno = SPI_fnumber(spi_ttc, "opcname");
505+
strcat(buf, "\"");
501506
strcat(buf, SPI_getvalue(spi_tup, spi_ttc, spi_fno));
507+
strcat(buf, "\"");
502508
}
503509
else
504510
/* ----------
@@ -628,29 +634,29 @@ make_ruledef(HeapTuple ruletup, TupleDesc rulettc)
628634
* Build the rules definition text
629635
* ----------
630636
*/
631-
strcpy(buf, "CREATE RULE ");
637+
strcpy(buf, "CREATE RULE \"");
632638

633639
/* The rule name */
634640
strcat(buf, rulename);
635-
strcat(buf, " AS ON ");
641+
strcat(buf, "\" AS ON ");
636642

637643
/* The event the rule is fired for */
638644
switch (ev_type)
639645
{
640646
case '1':
641-
strcat(buf, "SELECT TO ");
647+
strcat(buf, "SELECT TO \"");
642648
break;
643649

644650
case '2':
645-
strcat(buf, "UPDATE TO ");
651+
strcat(buf, "UPDATE TO \"");
646652
break;
647653

648654
case '3':
649-
strcat(buf, "INSERT TO ");
655+
strcat(buf, "INSERT TO \"");
650656
break;
651657

652658
case '4':
653-
strcat(buf, "DELETE TO ");
659+
strcat(buf, "DELETE TO \"");
654660
break;
655661

656662
default:
@@ -661,10 +667,12 @@ make_ruledef(HeapTuple ruletup, TupleDesc rulettc)
661667

662668
/* The relation the rule is fired on */
663669
strcat(buf, get_relation_name(ev_class));
670+
strcat(buf, "\"");
664671
if (ev_attr > 0)
665672
{
666-
strcat(buf, ".");
673+
strcat(buf, ".\"");
667674
strcat(buf, get_attribute_name(ev_class, ev_attr));
675+
strcat(buf, "\"");
668676
}
669677

670678
/* If the rule has an event qualification, add it */
@@ -941,8 +949,9 @@ get_select_query_def(Query *query, QryHier *qh)
941949
/* and do if so */
942950
if (tell_as)
943951
{
944-
strcat(buf, " AS ");
952+
strcat(buf, " AS \"");
945953
strcat(buf, tle->resdom->resname);
954+
strcat(buf, "\"");
946955
}
947956
}
948957

@@ -967,11 +976,14 @@ get_select_query_def(Query *query, QryHier *qh)
967976

968977
strcat(buf, sep);
969978
sep = ", ";
979+
strcat(buf, "\"");
970980
strcat(buf, rte->relname);
981+
strcat(buf, "\"");
971982
if (strcmp(rte->relname, rte->refname) != 0)
972983
{
973-
strcat(buf, " ");
984+
strcat(buf, " \"");
974985
strcat(buf, rte->refname);
986+
strcat(buf, "\"");
975987
}
976988
}
977989
}
@@ -1071,8 +1083,9 @@ get_insert_query_def(Query *query, QryHier *qh)
10711083
* ----------
10721084
*/
10731085
rte = (RangeTblEntry *) nth(query->resultRelation - 1, query->rtable);
1074-
strcpy(buf, "INSERT INTO ");
1086+
strcpy(buf, "INSERT INTO \"");
10751087
strcat(buf, rte->relname);
1088+
strcat(buf, "\"");
10761089

10771090
/* Add the target list */
10781091
sep = " (";
@@ -1082,7 +1095,9 @@ get_insert_query_def(Query *query, QryHier *qh)
10821095

10831096
strcat(buf, sep);
10841097
sep = ", ";
1098+
strcat(buf, "\"");
10851099
strcat(buf, tle->resdom->resname);
1100+
strcat(buf, "\"");
10861101
}
10871102
strcat(buf, ") ");
10881103

@@ -1142,8 +1157,9 @@ get_update_query_def(Query *query, QryHier *qh)
11421157

11431158
strcat(buf, sep);
11441159
sep = ", ";
1160+
strcat(buf, "\"");
11451161
strcat(buf, tle->resdom->resname);
1146-
strcat(buf, " = ");
1162+
strcat(buf, "\" = ");
11471163
strcat(buf, get_tle_expr(qh, query->resultRelation,
11481164
tle, TRUE));
11491165
}
@@ -1179,8 +1195,9 @@ get_delete_query_def(Query *query, QryHier *qh)
11791195
* ----------
11801196
*/
11811197
rte = (RangeTblEntry *) nth(query->resultRelation - 1, query->rtable);
1182-
strcpy(buf, "DELETE FROM ");
1198+
strcpy(buf, "DELETE FROM \"");
11831199
strcat(buf, rte->relname);
1200+
strcat(buf, "\"");
11841201

11851202
/* Add a WHERE clause if given */
11861203
if (query->qual != NULL)
@@ -1232,8 +1249,9 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix)
12321249
{
12331250
Aggreg *agg = (Aggreg *) node;
12341251

1252+
strcat(buf, "\"");
12351253
strcat(buf, agg->aggname);
1236-
strcat(buf, "(");
1254+
strcat(buf, "\"(");
12371255
strcat(buf, get_rule_expr(qh, rt_index,
12381256
(Node *) (agg->target), varprefix));
12391257
strcat(buf, ")");
@@ -1328,10 +1346,8 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix)
13281346
int sup = var->varlevelsup;
13291347

13301348
while(sup-- > 0) qh = qh->parent;
1331-
rte = (RangeTblEntry *) nth(var->varno - 1, qh->query->rtable);
13321349

1333-
if (qh->parent == NULL && var->varlevelsup > 0)
1334-
rte = (RangeTblEntry *) nth(var->varno + 1, qh->query->rtable);
1350+
rte = (RangeTblEntry *) nth(var->varno - 1, qh->query->rtable);
13351351

13361352
if (!strcmp(rte->refname, "*NEW*"))
13371353
strcat(buf, "new.");
@@ -1343,12 +1359,15 @@ get_rule_expr(QryHier *qh, int rt_index, Node *node, bool varprefix)
13431359
{
13441360
if (strcmp(rte->relname, rte->refname) != 0)
13451361
{
1362+
strcat(buf, "\"");
13461363
strcat(buf, rte->refname);
1347-
strcat(buf, ".");
1364+
strcat(buf, "\".");
13481365
}
13491366
}
13501367
}
1368+
strcat(buf, "\"");
13511369
strcat(buf, get_attribute_name(rte->relid, var->varattno));
1370+
strcat(buf, "\"");
13521371

13531372
return pstrdup(buf);
13541373
}
@@ -1433,8 +1452,9 @@ get_func_expr(QryHier *qh, int rt_index, Expr *expr, bool varprefix)
14331452
* Build a string of proname(args)
14341453
* ----------
14351454
*/
1436-
strcpy(buf, proname);
1437-
strcat(buf, "(");
1455+
strcpy(buf, "\"");
1456+
strcat(buf, proname);
1457+
strcat(buf, "\"(");
14381458
sep = "";
14391459
foreach(l, expr->args)
14401460
{
@@ -1561,7 +1581,7 @@ get_const_expr(Const *constval)
15611581
extval = (char *) (*fmgr_faddr(&finfo_output)) (constval->constvalue,
15621582
&isnull, -1);
15631583

1564-
sprintf(namebuf, "::%s", nameout(&(typeStruct->typname)));
1584+
sprintf(namebuf, "::\"%s\"", nameout(&(typeStruct->typname)));
15651585
if (strcmp(namebuf, "::unknown") == 0)
15661586
namebuf[0] = '\0';
15671587
sprintf(buf, "'%s'%s", extval, namebuf);

src/bin/pg_dump/common.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.26 1998/10/02 16:43:38 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.27 1998/10/06 22:14:17 momjian Exp $
1111
*
1212
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1313
*
@@ -304,6 +304,14 @@ dumpSchema(FILE *fout,
304304
tinfo, numTypes, tablename, acls);
305305
}
306306

307+
if (!tablename && fout)
308+
{
309+
if (g_verbose)
310+
fprintf(stderr, "%s dumping out user-defined procedural languages %s\n",
311+
g_comment_start, g_comment_end);
312+
dumpProcLangs(fout, finfo, numFuncs, tinfo, numTypes);
313+
}
314+
307315
if (!tablename && fout)
308316
{
309317
if (g_verbose)
@@ -315,7 +323,7 @@ dumpSchema(FILE *fout,
315323
if (!tablename && fout)
316324
{
317325
if (g_verbose)
318-
fprintf(stderr, "%s dumping out user-defined functions %s\n",
326+
fprintf(stderr, "%s dumping out user-defined aggregates %s\n",
319327
g_comment_start, g_comment_end);
320328
dumpAggs(fout, agginfo, numAggregates, tinfo, numTypes);
321329
}

0 commit comments

Comments
 (0)