From 694ce232f8784fea82975f30607e0158e66a107c Mon Sep 17 00:00:00 2001 From: li-judong Date: Fri, 8 Dec 2023 16:39:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DDELETE=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E8=A1=A8=E4=B8=8D=E6=98=AF=E6=99=AE=E9=80=9A=E8=A1=A8=E6=97=B6?= =?UTF-8?q?=E4=BA=A7=E7=94=9F=E7=9A=84core=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/parser/parse_clause.cpp | 5 +++++ src/test/regress/expected/multi_delete.out | 7 +++++++ src/test/regress/sql/multi_delete.sql | 6 ++++++ 3 files changed, 18 insertions(+) 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;