diff --git a/contrib/babelfishpg_tsql/src/tsql_analyze.c b/contrib/babelfishpg_tsql/src/tsql_analyze.c index b13b2f315f..16277f6c3f 100644 --- a/contrib/babelfishpg_tsql/src/tsql_analyze.c +++ b/contrib/babelfishpg_tsql/src/tsql_analyze.c @@ -124,7 +124,8 @@ pltsql_update_query_result_relation(Query *qry, Relation target_rel, List *rtabl for (int i = 0; i < list_length(rtable); i++) { RangeTblEntry *rte = (RangeTblEntry *) list_nth(rtable, i); - if (rte->relid == target_relid) + + if (rte->relid == target_relid && rte->rtekind != RTE_NAMEDTUPLESTORE) { qry->resultRelation = i + 1; return; diff --git a/test/JDBC/expected/BABEL-4606-vu-cleanup.out b/test/JDBC/expected/BABEL-4606-vu-cleanup.out new file mode 100644 index 0000000000..b2f49ddcd8 --- /dev/null +++ b/test/JDBC/expected/BABEL-4606-vu-cleanup.out @@ -0,0 +1,18 @@ +drop trigger babel_4606_trigger +go + +drop table babel_4606 +go + +drop trigger babel_4606_2_trigger +go + +drop table babel_4606_2 +go + +drop trigger babel_4606_3_trigger +go + +drop table babel_4606_3 +go + diff --git a/test/JDBC/expected/BABEL-4606-vu-prepare.out b/test/JDBC/expected/BABEL-4606-vu-prepare.out new file mode 100644 index 0000000000..ef746bd26e --- /dev/null +++ b/test/JDBC/expected/BABEL-4606-vu-prepare.out @@ -0,0 +1,61 @@ +create table babel_4606 (a int primary key, b int) +go + +insert into babel_4606 (a, b) values (1,7),(2,8),(3,9),(4,10),(5,11),(6,12) +go +~~ROW COUNT: 6~~ + + +create trigger babel_4606_trigger +on babel_4606 +after update +AS +begin + update t + set t.b = t.b + 1 + from inserted as i + join babel_4606 as t + on t.a = i.a +end +go + +create table babel_4606_2 (a int primary key, b int) +go + +insert into babel_4606_2 (a, b) values (1,7),(2,8),(3,9),(4,10),(5,11),(6,12) +go +~~ROW COUNT: 6~~ + + +create trigger babel_4606_2_trigger +on babel_4606_2 +after update +AS +begin + update babel_4606_2 + set babel_4606_2.b = babel_4606_2.b + 2 + from inserted as i + where babel_4606_2.a = i.a +end +go + +create table babel_4606_3 (a int primary key, b int) +go + +insert into babel_4606_3 (a, b) values (1,7),(2,8),(3,9),(4,10),(5,11),(6,12) +go +~~ROW COUNT: 6~~ + + +create trigger babel_4606_3_trigger +on babel_4606_3 +after update +AS +begin + update babel_4606_3 + set babel_4606_3.b = babel_4606_3.b + 200 + from deleted as i + where babel_4606_3.a = i.a +end +go + diff --git a/test/JDBC/expected/BABEL-4606-vu-verify.out b/test/JDBC/expected/BABEL-4606-vu-verify.out new file mode 100644 index 0000000000..c11a3fd2c3 --- /dev/null +++ b/test/JDBC/expected/BABEL-4606-vu-verify.out @@ -0,0 +1,98 @@ +select * from babel_4606 +GO +~~START~~ +int#!#int +1#!#7 +2#!#8 +3#!#9 +4#!#10 +5#!#11 +6#!#12 +~~END~~ + + +update babel_4606 set b = 100 where a = 1; +GO +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +select * from babel_4606 +GO +~~START~~ +int#!#int +2#!#8 +3#!#9 +4#!#10 +5#!#11 +6#!#12 +1#!#101 +~~END~~ + + +select * from babel_4606_2 +GO +~~START~~ +int#!#int +1#!#7 +2#!#8 +3#!#9 +4#!#10 +5#!#11 +6#!#12 +~~END~~ + + +update babel_4606_2 set b = 100 where a = 1; +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +select * from babel_4606_2 +GO +~~START~~ +int#!#int +2#!#8 +3#!#9 +4#!#10 +5#!#11 +6#!#12 +1#!#102 +~~END~~ + + +select * from babel_4606_3 +GO +~~START~~ +int#!#int +1#!#7 +2#!#8 +3#!#9 +4#!#10 +5#!#11 +6#!#12 +~~END~~ + + +update babel_4606_3 set b = 100 where a = 1; +go +~~ROW COUNT: 1~~ + +~~ROW COUNT: 1~~ + + +select * from babel_4606_3 +GO +~~START~~ +int#!#int +2#!#8 +3#!#9 +4#!#10 +5#!#11 +6#!#12 +1#!#300 +~~END~~ + diff --git a/test/JDBC/input/BABEL-4606-vu-cleanup.sql b/test/JDBC/input/BABEL-4606-vu-cleanup.sql new file mode 100644 index 0000000000..b2f49ddcd8 --- /dev/null +++ b/test/JDBC/input/BABEL-4606-vu-cleanup.sql @@ -0,0 +1,18 @@ +drop trigger babel_4606_trigger +go + +drop table babel_4606 +go + +drop trigger babel_4606_2_trigger +go + +drop table babel_4606_2 +go + +drop trigger babel_4606_3_trigger +go + +drop table babel_4606_3 +go + diff --git a/test/JDBC/input/BABEL-4606-vu-prepare.sql b/test/JDBC/input/BABEL-4606-vu-prepare.sql new file mode 100644 index 0000000000..b09639af4f --- /dev/null +++ b/test/JDBC/input/BABEL-4606-vu-prepare.sql @@ -0,0 +1,55 @@ +create table babel_4606 (a int primary key, b int) +go + +insert into babel_4606 (a, b) values (1,7),(2,8),(3,9),(4,10),(5,11),(6,12) +go + +create trigger babel_4606_trigger +on babel_4606 +after update +AS +begin + update t + set t.b = t.b + 1 + from inserted as i + join babel_4606 as t + on t.a = i.a +end +go + +create table babel_4606_2 (a int primary key, b int) +go + +insert into babel_4606_2 (a, b) values (1,7),(2,8),(3,9),(4,10),(5,11),(6,12) +go + +create trigger babel_4606_2_trigger +on babel_4606_2 +after update +AS +begin + update babel_4606_2 + set babel_4606_2.b = babel_4606_2.b + 2 + from inserted as i + where babel_4606_2.a = i.a +end +go + +create table babel_4606_3 (a int primary key, b int) +go + +insert into babel_4606_3 (a, b) values (1,7),(2,8),(3,9),(4,10),(5,11),(6,12) +go + +create trigger babel_4606_3_trigger +on babel_4606_3 +after update +AS +begin + update babel_4606_3 + set babel_4606_3.b = babel_4606_3.b + 200 + from deleted as i + where babel_4606_3.a = i.a +end +go + diff --git a/test/JDBC/input/BABEL-4606-vu-verify.sql b/test/JDBC/input/BABEL-4606-vu-verify.sql new file mode 100644 index 0000000000..f92164f747 --- /dev/null +++ b/test/JDBC/input/BABEL-4606-vu-verify.sql @@ -0,0 +1,26 @@ +select * from babel_4606 +GO + +update babel_4606 set b = 100 where a = 1; +GO + +select * from babel_4606 +GO + +select * from babel_4606_2 +GO + +update babel_4606_2 set b = 100 where a = 1; +go + +select * from babel_4606_2 +GO + +select * from babel_4606_3 +GO + +update babel_4606_3 set b = 100 where a = 1; +go + +select * from babel_4606_3 +GO diff --git a/test/JDBC/upgrade/14_10/schedule b/test/JDBC/upgrade/14_10/schedule index 5410a5f96e..bd75d176e2 100644 --- a/test/JDBC/upgrade/14_10/schedule +++ b/test/JDBC/upgrade/14_10/schedule @@ -419,3 +419,4 @@ BABEL-4231 sys_asymmetric_keys sys_certificates sys_database_permissions +BABEL-4606 diff --git a/test/JDBC/upgrade/14_8/schedule b/test/JDBC/upgrade/14_8/schedule index bbad4b287f..f466c5b88c 100644 --- a/test/JDBC/upgrade/14_8/schedule +++ b/test/JDBC/upgrade/14_8/schedule @@ -409,3 +409,4 @@ getdate BABEL_4330 AUTO_ANALYZE-before-15-5-or-14-10 BABEL_4389 +BABEL-4606 diff --git a/test/JDBC/upgrade/14_9/schedule b/test/JDBC/upgrade/14_9/schedule index 3b7f862adb..a3065677b1 100644 --- a/test/JDBC/upgrade/14_9/schedule +++ b/test/JDBC/upgrade/14_9/schedule @@ -412,3 +412,4 @@ smalldatetimefromparts-dep BABEL_4330 BABEL-4410 AUTO_ANALYZE-before-15-5-or-14-10 +BABEL-4606 diff --git a/test/JDBC/upgrade/latest/schedule b/test/JDBC/upgrade/latest/schedule index 27c4509273..757bd2ba0e 100644 --- a/test/JDBC/upgrade/latest/schedule +++ b/test/JDBC/upgrade/latest/schedule @@ -419,3 +419,4 @@ BABEL-4231 sys_asymmetric_keys sys_certificates sys_database_permissions +BABEL-4606