diff --git a/src/common/backend/parser/parse_clause.cpp b/src/common/backend/parser/parse_clause.cpp index c7f543d0a..a71a7f455 100644 --- a/src/common/backend/parser/parse_clause.cpp +++ b/src/common/backend/parser/parse_clause.cpp @@ -225,6 +225,11 @@ int setTargetTable(ParseState* pstate, RangeVar* relRv, bool inh, bool alsoSourc (errcode(ERRCODE_DUPLICATE_ALIAS), errmsg("table name \"%s\" specified more than once", relRv->alias->aliasname))); } else if (relRv->alias == NULL && strcmp(rte1->eref->aliasname, relRv->relname) == 0) { + if (rte1->rtekind != RTE_RELATION) { + ereport(ERROR, + (errcode(ERRCODE_OPERATE_NOT_SUPPORTED), + errmsg("The target table \"%s\" of the DELETE is not updatable", relRv->relname))); + } if (list_member_ptr(pstate->p_target_rangetblentry, rte1)) { ereport(ERROR, (errcode(ERRCODE_DUPLICATE_ALIAS), errmsg("table name \"%s\" specified more than once", diff --git a/src/test/regress/expected/multi_delete.out b/src/test/regress/expected/multi_delete.out index fada085d4..6c62a5806 100644 --- a/src/test/regress/expected/multi_delete.out +++ b/src/test/regress/expected/multi_delete.out @@ -1048,5 +1048,12 @@ select * from t_t_mutil_t2; drop view multiview1; drop view multiview2; drop view multiview3; +-- issue +WITH with_t1 AS ( SELECT TRUE AS c23 , -9213573085711696683 AS c49 ) DELETE with_t1 FROM with_t1; +ERROR: The target table "with_t1" of the DELETE is not updatable +DELETE subq_t1 FROM (SELECT 100 AS A) subq_t1; +ERROR: The target table "subq_t1" of the DELETE is not updatable +DELETE func_t1 FROM generate_series(1, 10) func_t1; +ERROR: The target table "func_t1" of the DELETE is not updatable \c regression drop database multidelete; diff --git a/src/test/regress/sql/multi_delete.sql b/src/test/regress/sql/multi_delete.sql index 849d38d1c..7be74aa3d 100644 --- a/src/test/regress/sql/multi_delete.sql +++ b/src/test/regress/sql/multi_delete.sql @@ -505,5 +505,11 @@ select * from t_t_mutil_t2; drop view multiview1; drop view multiview2; drop view multiview3; + +-- issue +WITH with_t1 AS ( SELECT TRUE AS c23 , -9213573085711696683 AS c49 ) DELETE with_t1 FROM with_t1; +DELETE subq_t1 FROM (SELECT 100 AS A) subq_t1; +DELETE func_t1 FROM generate_series(1, 10) func_t1; + \c regression drop database multidelete;