|
44 | 44 |
|
45 | 45 |
|
46 | 46 | staticvoidcheckRuleResultList(List*targetList,TupleDescresultDesc, |
47 | | -boolisSelect); |
| 47 | +boolisSelect,boolrequireColumnNameMatch); |
48 | 48 | staticboolsetRuleCheckAsUser_walker(Node*node,Oid*context); |
49 | 49 | staticvoidsetRuleCheckAsUser_Query(Query*qry,Oiduserid); |
50 | 50 |
|
@@ -355,7 +355,9 @@ DefineQueryRewrite(char *rulename, |
355 | 355 | */ |
356 | 356 | checkRuleResultList(query->targetList, |
357 | 357 | RelationGetDescr(event_relation), |
358 | | -true); |
| 358 | +true, |
| 359 | +event_relation->rd_rel->relkind!= |
| 360 | +RELKIND_MATVIEW); |
359 | 361 |
|
360 | 362 | /* |
361 | 363 | * ... 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 |
|
@@ -613,15 +615,20 @@ DefineQueryRewrite(char *rulename, |
613 | 615 | *Verify that targetList produces output compatible with a tupledesc |
614 | 616 | * |
615 | 617 | * The targetList might be either a SELECT targetlist, or a RETURNING list; |
616 | | - * isSelect tells which. (This is mostly used for choosing error messages, |
617 | | - * but also we don't enforce column name matching for RETURNING.) |
| 618 | + * isSelect tells which. This is used for choosing error messages. |
| 619 | + * |
| 620 | + * A SELECT targetlist may optionally require that column names match. |
618 | 621 | */ |
619 | 622 | staticvoid |
620 | | -checkRuleResultList(List*targetList,TupleDescresultDesc,boolisSelect) |
| 623 | +checkRuleResultList(List*targetList,TupleDescresultDesc,boolisSelect, |
| 624 | +boolrequireColumnNameMatch) |
621 | 625 | { |
622 | 626 | ListCell*tllist; |
623 | 627 | inti; |
624 | 628 |
|
| 629 | +/* Only a SELECT may require a column name match. */ |
| 630 | +Assert(isSelect|| !requireColumnNameMatch); |
| 631 | + |
625 | 632 | i=0; |
626 | 633 | foreach(tllist,targetList) |
627 | 634 | { |
@@ -657,7 +664,7 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect) |
657 | 664 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
658 | 665 | errmsg("cannot convert relation containing dropped columns to view"))); |
659 | 666 |
|
660 | | -if (isSelect&&strcmp(tle->resname,attname)!=0) |
| 667 | +if (requireColumnNameMatch&&strcmp(tle->resname,attname)!=0) |
661 | 668 | ereport(ERROR, |
662 | 669 | (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), |
663 | 670 | errmsg("SELECT rule's target entry %d has different column name from \"%s\"",i,attname))); |
|