Add compare_tables function for better testing

pull/7807/head
naisila 2024-12-27 12:25:09 +03:00 committed by Naisila Puka
parent ca673ed6a5
commit 034bb8cc0f
2 changed files with 192 additions and 310 deletions

View File

@ -2199,6 +2199,13 @@ RESET citus.log_remote_commands;
-- Relevant PG commit: -- Relevant PG commit:
-- https://github.com/postgres/postgres/commit/0294df2f1 -- https://github.com/postgres/postgres/commit/0294df2f1
SET citus.next_shard_id TO 25122024; SET citus.next_shard_id TO 25122024;
-- Regular Postgres tables
CREATE TABLE postgres_target_1 (tid integer, balance float, val text);
CREATE TABLE postgres_target_2 (tid integer, balance float, val text);
CREATE TABLE postgres_source (sid integer, delta float);
INSERT INTO postgres_target_1 SELECT id, id * 100, 'initial' FROM generate_series(1,15,2) AS id;
INSERT INTO postgres_target_2 SELECT id, id * 100, 'initial' FROM generate_series(1,15,2) AS id;
INSERT INTO postgres_source SELECT id, id * 10 FROM generate_series(1,14) AS id;
-- Citus local tables -- Citus local tables
CREATE TABLE citus_local_target (tid integer, balance float, val text); CREATE TABLE citus_local_target (tid integer, balance float, val text);
CREATE TABLE citus_local_source (sid integer, delta float); CREATE TABLE citus_local_source (sid integer, delta float);
@ -2235,52 +2242,90 @@ INSERT INTO citus_reference_source SELECT id, id * 10 FROM generate_series(1,14
-- Try all combinations of tables with two queries: -- Try all combinations of tables with two queries:
-- 1: Simple Merge -- 1: Simple Merge
-- 2: Merge with a constant qual -- 2: Merge with a constant qual
-- -- Run the merge queries with the postgres tables
-- Simple Merge expected output -- to save the expected output
-- tid | balance | val -- try simple MERGE
MERGE INTO postgres_target_1 t
USING postgres_source s
ON t.tid = s.sid
WHEN MATCHED THEN
UPDATE SET balance = balance + delta, val = val || ' updated by merge'
WHEN NOT MATCHED THEN
INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source';
SELECT * FROM postgres_target_1 ORDER BY tid, val;
tid | balance | val
--------------------------------------------------------------------- ---------------------------------------------------------------------
-- 1 | 110 | initial updated by merge 1 | 110 | initial updated by merge
-- 2 | 20 | inserted by merge 2 | 20 | inserted by merge
-- 3 | 330 | initial updated by merge 3 | 330 | initial updated by merge
-- 4 | 40 | inserted by merge 4 | 40 | inserted by merge
-- 5 | 550 | initial updated by merge 5 | 550 | initial updated by merge
-- 6 | 60 | inserted by merge 6 | 60 | inserted by merge
-- 7 | 770 | initial updated by merge 7 | 770 | initial updated by merge
-- 8 | 80 | inserted by merge 8 | 80 | inserted by merge
-- 9 | 990 | initial updated by merge 9 | 990 | initial updated by merge
-- 10 | 100 | inserted by merge 10 | 100 | inserted by merge
-- 11 | 1210 | initial updated by merge 11 | 1210 | initial updated by merge
-- 12 | 120 | inserted by merge 12 | 120 | inserted by merge
-- 13 | 1430 | initial updated by merge 13 | 1430 | initial updated by merge
-- 14 | 140 | inserted by merge 14 | 140 | inserted by merge
-- 15 | 1500 | initial not matched by source 15 | 1500 | initial not matched by source
-- (15 rows) (15 rows)
--
-- Merge with a constant qual expected output -- same with a constant qual
-- tid | balance | val MERGE INTO postgres_target_2 t
USING postgres_source s
ON t.tid = s.sid AND tid = 1
WHEN MATCHED THEN
UPDATE SET balance = balance + delta, val = val || ' updated by merge'
WHEN NOT MATCHED THEN
INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source';
SELECT * FROM postgres_target_2 ORDER BY tid, val;
tid | balance | val
--------------------------------------------------------------------- ---------------------------------------------------------------------
-- 1 | 110 | initial updated by merge 1 | 110 | initial updated by merge
-- 2 | 20 | inserted by merge 2 | 20 | inserted by merge
-- 3 | 300 | initial not matched by source 3 | 300 | initial not matched by source
-- 3 | 30 | inserted by merge 3 | 30 | inserted by merge
-- 4 | 40 | inserted by merge 4 | 40 | inserted by merge
-- 5 | 500 | initial not matched by source 5 | 500 | initial not matched by source
-- 5 | 50 | inserted by merge 5 | 50 | inserted by merge
-- 6 | 60 | inserted by merge 6 | 60 | inserted by merge
-- 7 | 700 | initial not matched by source 7 | 700 | initial not matched by source
-- 7 | 70 | inserted by merge 7 | 70 | inserted by merge
-- 8 | 80 | inserted by merge 8 | 80 | inserted by merge
-- 9 | 900 | initial not matched by source 9 | 900 | initial not matched by source
-- 9 | 90 | inserted by merge 9 | 90 | inserted by merge
-- 10 | 100 | inserted by merge 10 | 100 | inserted by merge
-- 11 | 1100 | initial not matched by source 11 | 1100 | initial not matched by source
-- 11 | 110 | inserted by merge 11 | 110 | inserted by merge
-- 12 | 120 | inserted by merge 12 | 120 | inserted by merge
-- 13 | 1300 | initial not matched by source 13 | 1300 | initial not matched by source
-- 13 | 130 | inserted by merge 13 | 130 | inserted by merge
-- 14 | 140 | inserted by merge 14 | 140 | inserted by merge
-- 15 | 1500 | initial not matched by source 15 | 1500 | initial not matched by source
-- (21 rows) (21 rows)
-- function to compare the output from Citus tables
-- with the expected output from Postgres tables
CREATE OR REPLACE FUNCTION compare_tables(table1 TEXT, table2 TEXT) RETURNS BOOLEAN AS $$
DECLARE ret BOOL;
BEGIN
EXECUTE 'select count(*) = 0 from ((
SELECT * FROM ' || table1 ||
' EXCEPT
SELECT * FROM ' || table2 || ' )
UNION ALL (
SELECT * FROM ' || table2 ||
' EXCEPT
SELECT * FROM ' || table1 || ' ))' INTO ret;
RETURN ret;
END
$$ LANGUAGE PLPGSQL;
-- Local-Local -- Local-Local
-- Let's also print the command here -- Let's also print the command here
-- try simple MERGE -- try simple MERGE
@ -2295,25 +2340,11 @@ MERGE INTO citus_local_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_local_target ORDER BY tid, val; SELECT compare_tables('citus_local_target', 'postgres_target_1');
tid | balance | val compare_tables
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 110 | initial updated by merge t
2 | 20 | inserted by merge (1 row)
3 | 330 | initial updated by merge
4 | 40 | inserted by merge
5 | 550 | initial updated by merge
6 | 60 | inserted by merge
7 | 770 | initial updated by merge
8 | 80 | inserted by merge
9 | 990 | initial updated by merge
10 | 100 | inserted by merge
11 | 1210 | initial updated by merge
12 | 120 | inserted by merge
13 | 1430 | initial updated by merge
14 | 140 | inserted by merge
15 | 1500 | initial not matched by source
(15 rows)
ROLLBACK; ROLLBACK;
-- same with a constant qual -- same with a constant qual
@ -2327,31 +2358,11 @@ MERGE INTO citus_local_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_local_target ORDER BY tid, val; SELECT compare_tables('citus_local_target', 'postgres_target_2');
tid | balance | val compare_tables
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 110 | initial updated by merge t
2 | 20 | inserted by merge (1 row)
3 | 300 | initial not matched by source
3 | 30 | inserted by merge
4 | 40 | inserted by merge
5 | 500 | initial not matched by source
5 | 50 | inserted by merge
6 | 60 | inserted by merge
7 | 700 | initial not matched by source
7 | 70 | inserted by merge
8 | 80 | inserted by merge
9 | 900 | initial not matched by source
9 | 90 | inserted by merge
10 | 100 | inserted by merge
11 | 1100 | initial not matched by source
11 | 110 | inserted by merge
12 | 120 | inserted by merge
13 | 1300 | initial not matched by source
13 | 130 | inserted by merge
14 | 140 | inserted by merge
15 | 1500 | initial not matched by source
(21 rows)
ROLLBACK; ROLLBACK;
-- Local-Reference -- Local-Reference
@ -2366,25 +2377,11 @@ MERGE INTO citus_local_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_local_target ORDER BY tid, val; SELECT compare_tables('citus_local_target', 'postgres_target_1');
tid | balance | val compare_tables
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 110 | initial updated by merge t
2 | 20 | inserted by merge (1 row)
3 | 330 | initial updated by merge
4 | 40 | inserted by merge
5 | 550 | initial updated by merge
6 | 60 | inserted by merge
7 | 770 | initial updated by merge
8 | 80 | inserted by merge
9 | 990 | initial updated by merge
10 | 100 | inserted by merge
11 | 1210 | initial updated by merge
12 | 120 | inserted by merge
13 | 1430 | initial updated by merge
14 | 140 | inserted by merge
15 | 1500 | initial not matched by source
(15 rows)
ROLLBACK; ROLLBACK;
-- same with a constant qual -- same with a constant qual
@ -2398,31 +2395,11 @@ MERGE INTO citus_local_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_local_target ORDER BY tid, val; SELECT compare_tables('citus_local_target', 'postgres_target_2');
tid | balance | val compare_tables
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 110 | initial updated by merge t
2 | 20 | inserted by merge (1 row)
3 | 300 | initial not matched by source
3 | 30 | inserted by merge
4 | 40 | inserted by merge
5 | 500 | initial not matched by source
5 | 50 | inserted by merge
6 | 60 | inserted by merge
7 | 700 | initial not matched by source
7 | 70 | inserted by merge
8 | 80 | inserted by merge
9 | 900 | initial not matched by source
9 | 90 | inserted by merge
10 | 100 | inserted by merge
11 | 1100 | initial not matched by source
11 | 110 | inserted by merge
12 | 120 | inserted by merge
13 | 1300 | initial not matched by source
13 | 130 | inserted by merge
14 | 140 | inserted by merge
15 | 1500 | initial not matched by source
(21 rows)
ROLLBACK; ROLLBACK;
-- Local-Distributed - Merge currently not supported, Feature in development. -- Local-Distributed - Merge currently not supported, Feature in development.
@ -2448,25 +2425,11 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_1');
tid | balance | val compare_tables
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 110 | initial updated by merge t
2 | 20 | inserted by merge (1 row)
3 | 330 | initial updated by merge
4 | 40 | inserted by merge
5 | 550 | initial updated by merge
6 | 60 | inserted by merge
7 | 770 | initial updated by merge
8 | 80 | inserted by merge
9 | 990 | initial updated by merge
10 | 100 | inserted by merge
11 | 1210 | initial updated by merge
12 | 120 | inserted by merge
13 | 1430 | initial updated by merge
14 | 140 | inserted by merge
15 | 1500 | initial not matched by source
(15 rows)
ROLLBACK; ROLLBACK;
-- same with a constant qual -- same with a constant qual
@ -2480,31 +2443,11 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_2');
tid | balance | val compare_tables
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 110 | initial updated by merge t
2 | 20 | inserted by merge (1 row)
3 | 300 | initial not matched by source
3 | 30 | inserted by merge
4 | 40 | inserted by merge
5 | 500 | initial not matched by source
5 | 50 | inserted by merge
6 | 60 | inserted by merge
7 | 700 | initial not matched by source
7 | 70 | inserted by merge
8 | 80 | inserted by merge
9 | 900 | initial not matched by source
9 | 90 | inserted by merge
10 | 100 | inserted by merge
11 | 1100 | initial not matched by source
11 | 110 | inserted by merge
12 | 120 | inserted by merge
13 | 1300 | initial not matched by source
13 | 130 | inserted by merge
14 | 140 | inserted by merge
15 | 1500 | initial not matched by source
(21 rows)
ROLLBACK; ROLLBACK;
-- Distributed-Distributed -- Distributed-Distributed
@ -2519,25 +2462,11 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_1');
tid | balance | val compare_tables
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 110 | initial updated by merge t
2 | 20 | inserted by merge (1 row)
3 | 330 | initial updated by merge
4 | 40 | inserted by merge
5 | 550 | initial updated by merge
6 | 60 | inserted by merge
7 | 770 | initial updated by merge
8 | 80 | inserted by merge
9 | 990 | initial updated by merge
10 | 100 | inserted by merge
11 | 1210 | initial updated by merge
12 | 120 | inserted by merge
13 | 1430 | initial updated by merge
14 | 140 | inserted by merge
15 | 1500 | initial not matched by source
(15 rows)
ROLLBACK; ROLLBACK;
-- same with a constant qual -- same with a constant qual
@ -2551,31 +2480,11 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_2');
tid | balance | val compare_tables
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 110 | initial updated by merge t
2 | 20 | inserted by merge (1 row)
3 | 300 | initial not matched by source
3 | 30 | inserted by merge
4 | 40 | inserted by merge
5 | 500 | initial not matched by source
5 | 50 | inserted by merge
6 | 60 | inserted by merge
7 | 700 | initial not matched by source
7 | 70 | inserted by merge
8 | 80 | inserted by merge
9 | 900 | initial not matched by source
9 | 90 | inserted by merge
10 | 100 | inserted by merge
11 | 1100 | initial not matched by source
11 | 110 | inserted by merge
12 | 120 | inserted by merge
13 | 1300 | initial not matched by source
13 | 130 | inserted by merge
14 | 140 | inserted by merge
15 | 1500 | initial not matched by source
(21 rows)
ROLLBACK; ROLLBACK;
-- Distributed-Reference -- Distributed-Reference
@ -2590,25 +2499,11 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_1');
tid | balance | val compare_tables
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 110 | initial updated by merge t
2 | 20 | inserted by merge (1 row)
3 | 330 | initial updated by merge
4 | 40 | inserted by merge
5 | 550 | initial updated by merge
6 | 60 | inserted by merge
7 | 770 | initial updated by merge
8 | 80 | inserted by merge
9 | 990 | initial updated by merge
10 | 100 | inserted by merge
11 | 1210 | initial updated by merge
12 | 120 | inserted by merge
13 | 1430 | initial updated by merge
14 | 140 | inserted by merge
15 | 1500 | initial not matched by source
(15 rows)
ROLLBACK; ROLLBACK;
-- same with a constant qual -- same with a constant qual
@ -2622,31 +2517,11 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_2');
tid | balance | val compare_tables
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 110 | initial updated by merge t
2 | 20 | inserted by merge (1 row)
3 | 300 | initial not matched by source
3 | 30 | inserted by merge
4 | 40 | inserted by merge
5 | 500 | initial not matched by source
5 | 50 | inserted by merge
6 | 60 | inserted by merge
7 | 700 | initial not matched by source
7 | 70 | inserted by merge
8 | 80 | inserted by merge
9 | 900 | initial not matched by source
9 | 90 | inserted by merge
10 | 100 | inserted by merge
11 | 1100 | initial not matched by source
11 | 110 | inserted by merge
12 | 120 | inserted by merge
13 | 1300 | initial not matched by source
13 | 130 | inserted by merge
14 | 140 | inserted by merge
15 | 1500 | initial not matched by source
(21 rows)
ROLLBACK; ROLLBACK;
-- Reference-N/A - Reference table as target is not allowed in Merge -- Reference-N/A - Reference table as target is not allowed in Merge

View File

@ -1086,6 +1086,14 @@ RESET citus.log_remote_commands;
SET citus.next_shard_id TO 25122024; SET citus.next_shard_id TO 25122024;
-- Regular Postgres tables
CREATE TABLE postgres_target_1 (tid integer, balance float, val text);
CREATE TABLE postgres_target_2 (tid integer, balance float, val text);
CREATE TABLE postgres_source (sid integer, delta float);
INSERT INTO postgres_target_1 SELECT id, id * 100, 'initial' FROM generate_series(1,15,2) AS id;
INSERT INTO postgres_target_2 SELECT id, id * 100, 'initial' FROM generate_series(1,15,2) AS id;
INSERT INTO postgres_source SELECT id, id * 10 FROM generate_series(1,14) AS id;
-- Citus local tables -- Citus local tables
CREATE TABLE citus_local_target (tid integer, balance float, val text); CREATE TABLE citus_local_target (tid integer, balance float, val text);
CREATE TABLE citus_local_source (sid integer, delta float); CREATE TABLE citus_local_source (sid integer, delta float);
@ -1111,52 +1119,51 @@ INSERT INTO citus_reference_source SELECT id, id * 10 FROM generate_series(1,14
-- Try all combinations of tables with two queries: -- Try all combinations of tables with two queries:
-- 1: Simple Merge -- 1: Simple Merge
-- 2: Merge with a constant qual -- 2: Merge with a constant qual
--
-- Simple Merge expected output -- Run the merge queries with the postgres tables
-- tid | balance | val -- to save the expected output
-----+---------+-------------------------------
-- 1 | 110 | initial updated by merge -- try simple MERGE
-- 2 | 20 | inserted by merge MERGE INTO postgres_target_1 t
-- 3 | 330 | initial updated by merge USING postgres_source s
-- 4 | 40 | inserted by merge ON t.tid = s.sid
-- 5 | 550 | initial updated by merge WHEN MATCHED THEN
-- 6 | 60 | inserted by merge UPDATE SET balance = balance + delta, val = val || ' updated by merge'
-- 7 | 770 | initial updated by merge WHEN NOT MATCHED THEN
-- 8 | 80 | inserted by merge INSERT VALUES (sid, delta, 'inserted by merge')
-- 9 | 990 | initial updated by merge WHEN NOT MATCHED BY SOURCE THEN
-- 10 | 100 | inserted by merge UPDATE SET val = val || ' not matched by source';
-- 11 | 1210 | initial updated by merge SELECT * FROM postgres_target_1 ORDER BY tid, val;
-- 12 | 120 | inserted by merge
-- 13 | 1430 | initial updated by merge -- same with a constant qual
-- 14 | 140 | inserted by merge MERGE INTO postgres_target_2 t
-- 15 | 1500 | initial not matched by source USING postgres_source s
-- (15 rows) ON t.tid = s.sid AND tid = 1
-- WHEN MATCHED THEN
-- Merge with a constant qual expected output UPDATE SET balance = balance + delta, val = val || ' updated by merge'
-- tid | balance | val WHEN NOT MATCHED THEN
-----+---------+------------------------------- INSERT VALUES (sid, delta, 'inserted by merge')
-- 1 | 110 | initial updated by merge WHEN NOT MATCHED BY SOURCE THEN
-- 2 | 20 | inserted by merge UPDATE SET val = val || ' not matched by source';
-- 3 | 300 | initial not matched by source SELECT * FROM postgres_target_2 ORDER BY tid, val;
-- 3 | 30 | inserted by merge
-- 4 | 40 | inserted by merge -- function to compare the output from Citus tables
-- 5 | 500 | initial not matched by source -- with the expected output from Postgres tables
-- 5 | 50 | inserted by merge
-- 6 | 60 | inserted by merge CREATE OR REPLACE FUNCTION compare_tables(table1 TEXT, table2 TEXT) RETURNS BOOLEAN AS $$
-- 7 | 700 | initial not matched by source DECLARE ret BOOL;
-- 7 | 70 | inserted by merge BEGIN
-- 8 | 80 | inserted by merge EXECUTE 'select count(*) = 0 from ((
-- 9 | 900 | initial not matched by source SELECT * FROM ' || table1 ||
-- 9 | 90 | inserted by merge ' EXCEPT
-- 10 | 100 | inserted by merge SELECT * FROM ' || table2 || ' )
-- 11 | 1100 | initial not matched by source UNION ALL (
-- 11 | 110 | inserted by merge SELECT * FROM ' || table2 ||
-- 12 | 120 | inserted by merge ' EXCEPT
-- 13 | 1300 | initial not matched by source SELECT * FROM ' || table1 || ' ))' INTO ret;
-- 13 | 130 | inserted by merge RETURN ret;
-- 14 | 140 | inserted by merge END
-- 15 | 1500 | initial not matched by source $$ LANGUAGE PLPGSQL;
-- (21 rows)
-- Local-Local -- Local-Local
-- Let's also print the command here -- Let's also print the command here
@ -1172,7 +1179,7 @@ MERGE INTO citus_local_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_local_target ORDER BY tid, val; SELECT compare_tables('citus_local_target', 'postgres_target_1');
ROLLBACK; ROLLBACK;
-- same with a constant qual -- same with a constant qual
@ -1186,7 +1193,7 @@ MERGE INTO citus_local_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_local_target ORDER BY tid, val; SELECT compare_tables('citus_local_target', 'postgres_target_2');
ROLLBACK; ROLLBACK;
-- Local-Reference -- Local-Reference
@ -1201,7 +1208,7 @@ MERGE INTO citus_local_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_local_target ORDER BY tid, val; SELECT compare_tables('citus_local_target', 'postgres_target_1');
ROLLBACK; ROLLBACK;
-- same with a constant qual -- same with a constant qual
@ -1215,7 +1222,7 @@ MERGE INTO citus_local_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_local_target ORDER BY tid, val; SELECT compare_tables('citus_local_target', 'postgres_target_2');
ROLLBACK; ROLLBACK;
-- Local-Distributed - Merge currently not supported, Feature in development. -- Local-Distributed - Merge currently not supported, Feature in development.
@ -1242,7 +1249,7 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_1');
ROLLBACK; ROLLBACK;
-- same with a constant qual -- same with a constant qual
@ -1256,7 +1263,7 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_2');
ROLLBACK; ROLLBACK;
-- Distributed-Distributed -- Distributed-Distributed
@ -1271,7 +1278,7 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_1');
ROLLBACK; ROLLBACK;
-- same with a constant qual -- same with a constant qual
@ -1285,7 +1292,7 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_2');
ROLLBACK; ROLLBACK;
-- Distributed-Reference -- Distributed-Reference
@ -1300,7 +1307,7 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_1');
ROLLBACK; ROLLBACK;
-- same with a constant qual -- same with a constant qual
@ -1314,7 +1321,7 @@ MERGE INTO citus_distributed_target t
INSERT VALUES (sid, delta, 'inserted by merge') INSERT VALUES (sid, delta, 'inserted by merge')
WHEN NOT MATCHED BY SOURCE THEN WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET val = val || ' not matched by source'; UPDATE SET val = val || ' not matched by source';
SELECT * FROM citus_distributed_target ORDER BY tid, val; SELECT compare_tables('citus_distributed_target', 'postgres_target_2');
ROLLBACK; ROLLBACK;
-- Reference-N/A - Reference table as target is not allowed in Merge -- Reference-N/A - Reference table as target is not allowed in Merge