|
43 | 43 |
|
44 | 44 |
|
45 | 45 | static void checkRuleResultList(List *targetList, TupleDesc resultDesc,
|
46 |
| - bool isSelect); |
| 46 | + bool isSelect, bool requireColumnNameMatch); |
47 | 47 | static bool setRuleCheckAsUser_walker(Node *node, Oid *context);
|
48 | 48 | static void setRuleCheckAsUser_Query(Query *qry, Oid userid);
|
49 | 49 |
|
@@ -358,7 +358,9 @@ DefineQueryRewrite(char *rulename,
|
358 | 358 | */
|
359 | 359 | checkRuleResultList(query->targetList,
|
360 | 360 | RelationGetDescr(event_relation),
|
361 |
| - true); |
| 361 | + true, |
| 362 | + event_relation->rd_rel->relkind != |
| 363 | + RELKIND_MATVIEW); |
362 | 364 |
|
363 | 365 | /*
|
364 | 366 | * ... there must not be another ON SELECT rule already ...
|
@@ -484,7 +486,7 @@ DefineQueryRewrite(char *rulename,
|
484 | 486 | errmsg("RETURNING lists are not supported in non-INSTEAD rules")));
|
485 | 487 | checkRuleResultList(query->returningList,
|
486 | 488 | RelationGetDescr(event_relation),
|
487 |
| - false); |
| 489 | + false, false); |
488 | 490 | }
|
489 | 491 | }
|
490 | 492 |
|
@@ -616,15 +618,20 @@ DefineQueryRewrite(char *rulename,
|
616 | 618 | * Verify that targetList produces output compatible with a tupledesc
|
617 | 619 | *
|
618 | 620 | * The targetList might be either a SELECT targetlist, or a RETURNING list;
|
619 |
| - * isSelect tells which. (This is mostly used for choosing error messages, |
620 |
| - * but also we don't enforce column name matching for RETURNING.) |
| 621 | + * isSelect tells which. This is used for choosing error messages. |
| 622 | + * |
| 623 | + * A SELECT targetlist may optionally require that column names match. |
621 | 624 | */
|
622 | 625 | static void
|
623 |
| -checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect) |
| 626 | +checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect, |
| 627 | + bool requireColumnNameMatch) |
624 | 628 | {
|
625 | 629 | ListCell *tllist;
|
626 | 630 | int i;
|
627 | 631 |
|
| 632 | + /* Only a SELECT may require a column name match. */ |
| 633 | + Assert(isSelect || !requireColumnNameMatch); |
| 634 | + |
628 | 635 | i = 0;
|
629 | 636 | foreach(tllist, targetList)
|
630 | 637 | {
|
@@ -660,7 +667,7 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect)
|
660 | 667 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
661 | 668 | errmsg("cannot convert relation containing dropped columns to view")));
|
662 | 669 |
|
663 |
| - if (isSelect && strcmp(tle->resname, attname) != 0) |
| 670 | + if (requireColumnNameMatch && strcmp(tle->resname, attname) != 0) |
664 | 671 | ereport(ERROR,
|
665 | 672 | (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
666 | 673 | errmsg("SELECT rule's target entry %d has different column name from \"%s\"", i, attname)));
|
|
0 commit comments