diff options
author | Kevin Grittner <kgrittn@postgresql.org> | 2013-11-04 14:31:07 -0600 |
---|---|---|
committer | Kevin Grittner <kgrittn@postgresql.org> | 2013-11-04 14:31:07 -0600 |
commit | 732758db4c8226b74a6ea7a90bc8c3cd15f5fe86 (patch) | |
tree | 08079cbe53a80e58b59dbf785f1d272ea0aaa999 /src/backend/rewrite/rewriteDefine.c | |
parent | dddc34408aa6ca535e89cb26653014bb019bc263 (diff) |
Fix breakage of MV column name list usage.
Per bug report from Tomonari Katsumata.
Back-patch to 9.3.
Diffstat (limited to 'src/backend/rewrite/rewriteDefine.c')
-rw-r--r-- | src/backend/rewrite/rewriteDefine.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/backend/rewrite/rewriteDefine.c b/src/backend/rewrite/rewriteDefine.c index 9c4a5d47e28..2eca531749a 100644 --- a/src/backend/rewrite/rewriteDefine.c +++ b/src/backend/rewrite/rewriteDefine.c @@ -44,7 +44,7 @@ static void checkRuleResultList(List *targetList, TupleDesc resultDesc, - bool isSelect); + bool isSelect, bool requireColumnNameMatch); static bool setRuleCheckAsUser_walker(Node *node, Oid *context); static void setRuleCheckAsUser_Query(Query *qry, Oid userid); @@ -355,7 +355,9 @@ DefineQueryRewrite(char *rulename, */ checkRuleResultList(query->targetList, RelationGetDescr(event_relation), - true); + true, + event_relation->rd_rel->relkind != + RELKIND_MATVIEW); /* * ... there must not be another ON SELECT rule already ... @@ -484,7 +486,7 @@ DefineQueryRewrite(char *rulename, errmsg("RETURNING lists are not supported in non-INSTEAD rules"))); checkRuleResultList(query->returningList, RelationGetDescr(event_relation), - false); + false, false); } } @@ -613,15 +615,20 @@ DefineQueryRewrite(char *rulename, * Verify that targetList produces output compatible with a tupledesc * * The targetList might be either a SELECT targetlist, or a RETURNING list; - * isSelect tells which. (This is mostly used for choosing error messages, - * but also we don't enforce column name matching for RETURNING.) + * isSelect tells which. This is used for choosing error messages. + * + * A SELECT targetlist may optionally require that column names match. */ static void -checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect) +checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect, + bool requireColumnNameMatch) { ListCell *tllist; int i; + /* Only a SELECT may require a column name match. */ + Assert(isSelect || !requireColumnNameMatch); + i = 0; foreach(tllist, targetList) { @@ -657,7 +664,7 @@ checkRuleResultList(List *targetList, TupleDesc resultDesc, bool isSelect) (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot convert relation containing dropped columns to view"))); - if (isSelect && strcmp(tle->resname, attname) != 0) + if (requireColumnNameMatch && strcmp(tle->resname, attname) != 0) ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), errmsg("SELECT rule's target entry %d has different column name from \"%s\"", i, attname))); |