From: Dean Rasheed Date: Fri, 25 Nov 2022 13:31:48 +0000 (+0000) Subject: Fix rule-detection code for MERGE. X-Git-Tag: REL_16_BETA1~1232 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=7b2ccc5e03bf16d1e1bbabca25298108c839ec52;p=postgresql.git Fix rule-detection code for MERGE. Use the relation's rd_rules structure to test whether it has rules, rather than the relhasrules flag, which might be out of date. Reviewed by Tom Lane. Backpatch to 15, where MERGE was added. Discussion: https://postgr.es/m/CAEZATCVkBVZABfw71sYvkcPf6tarcOFST5Bc6AOi-LFT9YdccQ%40mail.gmail.com --- diff --git a/src/backend/parser/parse_merge.c b/src/backend/parser/parse_merge.c index 7913523b1c6..62c2ff69f0c 100644 --- a/src/backend/parser/parse_merge.c +++ b/src/backend/parser/parse_merge.c @@ -182,7 +182,8 @@ transformMergeStmt(ParseState *pstate, MergeStmt *stmt) errmsg("cannot execute MERGE on relation \"%s\"", RelationGetRelationName(pstate->p_target_relation)), errdetail_relkind_not_supported(pstate->p_target_relation->rd_rel->relkind))); - if (pstate->p_target_relation->rd_rel->relhasrules) + if (pstate->p_target_relation->rd_rules != NULL && + pstate->p_target_relation->rd_rules->numLocks > 0) ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), errmsg("cannot execute MERGE on relation \"%s\"",