处理issue:merge into源为物化视图,报错cannot lock rows in materialized view

This commit is contained in:
lukeman
2024-08-15 19:27:09 +08:00
parent e53432eda6
commit 8d2ce084e5
3 changed files with 55 additions and 5 deletions

View File

@ -1786,11 +1786,13 @@ static void CheckValidRowMarkRel(Relation rel, RowMarkType markType)
errmsg("cannot lock rows in contview \"%s\"", RelationGetRelationName(rel))));
break;
case RELKIND_MATVIEW:
/* Should not get here */
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot lock rows in materialized view \"%s\"",
RelationGetRelationName(rel))));
/* Allow referencing a matview, but not actual locking clauses */
if (markType != ROW_MARK_REFERENCE) {
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot lock rows in materialized view \"%s\"",
RelationGetRelationName(rel))));
}
break;
case RELKIND_FOREIGN_TABLE:
/* Should not get here; planner should have used ROW_MARK_COPY */

View File

@ -134,6 +134,30 @@ select c1, c2, to_char(c3, 'yyyy-mm-dd') from t1 order by c1;
4 | e | 2023-09-19
(2 rows)
-- materialized view
drop table if exists t_a;
NOTICE: table "t_a" does not exist, skipping
drop table if exists t_b;
NOTICE: table "t_b" does not exist, skipping
create table t_a(
a_id int,
a_name varchar2(100)
);
create table t_b(
b_id int,
b_name varchar2(100)
);
DROP materialized VIEW if exists v_t_b;
NOTICE: materialized view "v_t_b" does not exist, skipping
create materialized view v_t_b as select * from t_b;
MERGE INTO t_a a
USING v_t_b vb
on (a.a_id=vb.b_id)
WHEN MATCHED THEN
update set a.a_name=vb.b_name;
DROP materialized VIEW v_t_b;
drop table t_a;
drop table t_b;
drop schema merge_into_updated cascade;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table t1

View File

@ -115,4 +115,28 @@ end;
\parallel off
select c1, c2, to_char(c3, 'yyyy-mm-dd') from t1 order by c1;
-- materialized view
drop table if exists t_a;
drop table if exists t_b;
create table t_a(
a_id int,
a_name varchar2(100)
);
create table t_b(
b_id int,
b_name varchar2(100)
);
DROP materialized VIEW if exists v_t_b;
create materialized view v_t_b as select * from t_b;
MERGE INTO t_a a
USING v_t_b vb
on (a.a_id=vb.b_id)
WHEN MATCHED THEN
update set a.a_name=vb.b_name;
DROP materialized VIEW v_t_b;
drop table t_a;
drop table t_b;
drop schema merge_into_updated cascade;