Debian Codegraph @

src/test/subscription/t/002_types.pl

raw
1
2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
3
4 # This tests that more complex datatypes are replicated correctly
5 # by logical replication
6 use strict;
7 use warnings FATAL => 'all';
8 use PostgreSQL::Test::Cluster;
9 use PostgreSQL::Test::Utils;
10 use Test::More;
11
12 # Initialize publisher node
13 my $node_publisher = PostgreSQL::Test::Cluster->new('publisher');
14 $node_publisher->init(allows_streaming => 'logical');
15 $node_publisher->start;
16
17 # Create subscriber node
18 my $node_subscriber = PostgreSQL::Test::Cluster->new('subscriber');
19 $node_subscriber->init;
20 $node_subscriber->start;
21
22 # Create some preexisting content on publisher
23 my $ddl = qq(
24 CREATE EXTENSION hstore WITH SCHEMA public;
25 CREATE TABLE public.tst_one_array (
26 a INTEGER PRIMARY KEY,
27 b INTEGER[]
28 );
29 CREATE TABLE public.tst_arrays (
30 a INTEGER[] PRIMARY KEY,
31 b TEXT[],
32 c FLOAT[],
33 d INTERVAL[]
34 );
35
36 CREATE TYPE public.tst_enum_t AS ENUM ('a', 'b', 'c', 'd', 'e');
37 CREATE TABLE public.tst_one_enum (
38 a INTEGER PRIMARY KEY,
39 b public.tst_enum_t
40 );
41 CREATE TABLE public.tst_enums (
42 a public.tst_enum_t PRIMARY KEY,
43 b public.tst_enum_t[]
44 );
45
46 CREATE TYPE public.tst_comp_basic_t AS (a FLOAT, b TEXT, c INTEGER);
47 CREATE TYPE public.tst_comp_enum_t AS (a FLOAT, b public.tst_enum_t, c INTEGER);
48 CREATE TYPE public.tst_comp_enum_array_t AS (a FLOAT, b public.tst_enum_t[], c INTEGER);
49 CREATE TABLE public.tst_one_comp (
50 a INTEGER PRIMARY KEY,
51 b public.tst_comp_basic_t
52 );
53 CREATE TABLE public.tst_comps (
54 a public.tst_comp_basic_t PRIMARY KEY,
55 b public.tst_comp_basic_t[]
56 );
57 CREATE TABLE public.tst_comp_enum (
58 a INTEGER PRIMARY KEY,
59 b public.tst_comp_enum_t
60 );
61 CREATE TABLE public.tst_comp_enum_array (
62 a public.tst_comp_enum_t PRIMARY KEY,
63 b public.tst_comp_enum_t[]
64 );
65 CREATE TABLE public.tst_comp_one_enum_array (
66 a INTEGER PRIMARY KEY,
67 b public.tst_comp_enum_array_t
68 );
69 CREATE TABLE public.tst_comp_enum_what (
70 a public.tst_comp_enum_array_t PRIMARY KEY,
71 b public.tst_comp_enum_array_t[]
72 );
73
74 CREATE TYPE public.tst_comp_mix_t AS (
75 a public.tst_comp_basic_t,
76 b public.tst_comp_basic_t[],
77 c public.tst_enum_t,
78 d public.tst_enum_t[]
79 );
80 CREATE TABLE public.tst_comp_mix_array (
81 a public.tst_comp_mix_t PRIMARY KEY,
82 b public.tst_comp_mix_t[]
83 );
84 CREATE TABLE public.tst_range (
85 a INTEGER PRIMARY KEY,
86 b int4range
87 );
88 CREATE TABLE public.tst_range_array (
89 a INTEGER PRIMARY KEY,
90 b TSTZRANGE,
91 c int8range[]
92 );
93 CREATE TABLE public.tst_hstore (
94 a INTEGER PRIMARY KEY,
95 b public.hstore
96 );
97
98 SET check_function_bodies=off;
99 CREATE FUNCTION public.monot_incr(int) RETURNS bool LANGUAGE sql
100 AS ' select \$1 > max(a) from public.tst_dom_constr; ';
101 CREATE DOMAIN monot_int AS int CHECK (monot_incr(VALUE));
102 CREATE TABLE public.tst_dom_constr (a monot_int););
103
104 # Setup structure on both nodes
105 $node_publisher->safe_psql('postgres', $ddl);
106 $node_subscriber->safe_psql('postgres', $ddl);
107
108 # Setup logical replication
109 my $publisher_connstr = $node_publisher->connstr . ' dbname=postgres';
110 $node_publisher->safe_psql('postgres',
111 "CREATE PUBLICATION tap_pub FOR ALL TABLES");
112
113 $node_subscriber->safe_psql('postgres',
114 "CREATE SUBSCRIPTION tap_sub CONNECTION '$publisher_connstr' PUBLICATION tap_pub WITH (slot_name = tap_sub_slot)"
115 );
116
117 # Wait for initial sync to finish as well
118 $node_subscriber->wait_for_subscription_sync($node_publisher, 'tap_sub');
119
120 # Insert initial test data
121 $node_publisher->safe_psql(
122 'postgres', qq(
123 -- test_tbl_one_array_col
124 INSERT INTO tst_one_array (a, b) VALUES
125 (1, '{1, 2, 3}'),
126 (2, '{2, 3, 1}'),
127 (3, '{3, 2, 1}'),
128 (4, '{4, 3, 2}'),
129 (5, '{5, NULL, 3}');
130
131 -- test_tbl_arrays
132 INSERT INTO tst_arrays (a, b, c, d) VALUES
133 ('{1, 2, 3}', '{"a", "b", "c"}', '{1.1, 2.2, 3.3}', '{"1 day", "2 days", "3 days"}'),
134 ('{2, 3, 1}', '{"b", "c", "a"}', '{2.2, 3.3, 1.1}', '{"2 minutes", "3 minutes", "1 minute"}'),
135 ('{3, 1, 2}', '{"c", "a", "b"}', '{3.3, 1.1, 2.2}', '{"3 years", "1 year", "2 years"}'),
136 ('{4, 1, 2}', '{"d", "a", "b"}', '{4.4, 1.1, 2.2}', '{"4 years", "1 year", "2 years"}'),
137 ('{5, NULL, NULL}', '{"e", NULL, "b"}', '{5.5, 1.1, NULL}', '{"5 years", NULL, NULL}');
138
139 -- test_tbl_single_enum
140 INSERT INTO tst_one_enum (a, b) VALUES
141 (1, 'a'),
142 (2, 'b'),
143 (3, 'c'),
144 (4, 'd'),
145 (5, NULL);
146
147 -- test_tbl_enums
148 INSERT INTO tst_enums (a, b) VALUES
149 ('a', '{b, c}'),
150 ('b', '{c, a}'),
151 ('c', '{b, a}'),
152 ('d', '{c, b}'),
153 ('e', '{d, NULL}');
154
155 -- test_tbl_single_composites
156 INSERT INTO tst_one_comp (a, b) VALUES
157 (1, ROW(1.0, 'a', 1)),
158 (2, ROW(2.0, 'b', 2)),
159 (3, ROW(3.0, 'c', 3)),
160 (4, ROW(4.0, 'd', 4)),
161 (5, ROW(NULL, NULL, 5));
162
163 -- test_tbl_composites
164 INSERT INTO tst_comps (a, b) VALUES
165 (ROW(1.0, 'a', 1), ARRAY[ROW(1, 'a', 1)::tst_comp_basic_t]),
166 (ROW(2.0, 'b', 2), ARRAY[ROW(2, 'b', 2)::tst_comp_basic_t]),
167 (ROW(3.0, 'c', 3), ARRAY[ROW(3, 'c', 3)::tst_comp_basic_t]),
168 (ROW(4.0, 'd', 4), ARRAY[ROW(4, 'd', 3)::tst_comp_basic_t]),
169 (ROW(5.0, 'e', NULL), ARRAY[NULL, ROW(5, NULL, 5)::tst_comp_basic_t]);
170
171 -- test_tbl_composite_with_enums
172 INSERT INTO tst_comp_enum (a, b) VALUES
173 (1, ROW(1.0, 'a', 1)),
174 (2, ROW(2.0, 'b', 2)),
175 (3, ROW(3.0, 'c', 3)),
176 (4, ROW(4.0, 'd', 4)),
177 (5, ROW(NULL, 'e', NULL));
178
179 -- test_tbl_composite_with_enums_array
180 INSERT INTO tst_comp_enum_array (a, b) VALUES
181 (ROW(1.0, 'a', 1), ARRAY[ROW(1, 'a', 1)::tst_comp_enum_t]),
182 (ROW(2.0, 'b', 2), ARRAY[ROW(2, 'b', 2)::tst_comp_enum_t]),
183 (ROW(3.0, 'c', 3), ARRAY[ROW(3, 'c', 3)::tst_comp_enum_t]),
184 (ROW(4.0, 'd', 3), ARRAY[ROW(3, 'd', 3)::tst_comp_enum_t]),
185 (ROW(5.0, 'e', 3), ARRAY[ROW(3, 'e', 3)::tst_comp_enum_t, NULL]);
186
187 -- test_tbl_composite_with_single_enums_array_in_composite
188 INSERT INTO tst_comp_one_enum_array (a, b) VALUES
189 (1, ROW(1.0, '{a, b, c}', 1)),
190 (2, ROW(2.0, '{a, b, c}', 2)),
191 (3, ROW(3.0, '{a, b, c}', 3)),
192 (4, ROW(4.0, '{c, b, d}', 4)),
193 (5, ROW(5.0, '{NULL, e, NULL}', 5));
194
195 -- test_tbl_composite_with_enums_array_in_composite
196 INSERT INTO tst_comp_enum_what (a, b) VALUES
197 (ROW(1.0, '{a, b, c}', 1), ARRAY[ROW(1, '{a, b, c}', 1)::tst_comp_enum_array_t]),
198 (ROW(2.0, '{b, c, a}', 2), ARRAY[ROW(2, '{b, c, a}', 1)::tst_comp_enum_array_t]),
199 (ROW(3.0, '{c, a, b}', 1), ARRAY[ROW(3, '{c, a, b}', 1)::tst_comp_enum_array_t]),
200 (ROW(4.0, '{c, b, d}', 4), ARRAY[ROW(4, '{c, b, d}', 4)::tst_comp_enum_array_t]),
201 (ROW(5.0, '{c, NULL, b}', NULL), ARRAY[ROW(5, '{c, e, b}', 1)::tst_comp_enum_array_t]);
202
203 -- test_tbl_mixed_composites
204 INSERT INTO tst_comp_mix_array (a, b) VALUES
205 (ROW(
206 ROW(1,'a',1),
207 ARRAY[ROW(1,'a',1)::tst_comp_basic_t, ROW(2,'b',2)::tst_comp_basic_t],
208 'a',
209 '{a,b,NULL,c}'),
210 ARRAY[
211 ROW(
212 ROW(1,'a',1),
213 ARRAY[
214 ROW(1,'a',1)::tst_comp_basic_t,
215 ROW(2,'b',2)::tst_comp_basic_t,
216 NULL
217 ],
218 'a',
219 '{a,b,c}'
220 )::tst_comp_mix_t
221 ]
222 );
223
224 -- test_tbl_range
225 INSERT INTO tst_range (a, b) VALUES
226 (1, '[1, 10]'),
227 (2, '[2, 20]'),
228 (3, '[3, 30]'),
229 (4, '[4, 40]'),
230 (5, '[5, 50]');
231
232 -- test_tbl_range_array
233 INSERT INTO tst_range_array (a, b, c) VALUES
234 (1, tstzrange('Mon Aug 04 00:00:00 2014 CEST'::timestamptz, 'infinity'), '{"[1,2]", "[10,20]"}'),
235 (2, tstzrange('Sat Aug 02 00:00:00 2014 CEST'::timestamptz, 'Mon Aug 04 00:00:00 2014 CEST'::timestamptz), '{"[2,3]", "[20,30]"}'),
236 (3, tstzrange('Fri Aug 01 00:00:00 2014 CEST'::timestamptz, 'Mon Aug 04 00:00:00 2014 CEST'::timestamptz), '{"[3,4]"}'),
237 (4, tstzrange('Thu Jul 31 00:00:00 2014 CEST'::timestamptz, 'Mon Aug 04 00:00:00 2014 CEST'::timestamptz), '{"[4,5]", NULL, "[40,50]"}'),
238 (5, NULL, NULL);
239
240 -- tst_hstore
241 INSERT INTO tst_hstore (a, b) VALUES
242 (1, '"a"=>"1"'),
243 (2, '"zzz"=>"foo"'),
244 (3, '"123"=>"321"'),
245 (4, '"yellow horse"=>"moaned"');
246
247 -- tst_dom_constr
248 INSERT INTO tst_dom_constr VALUES (10);
249 ));
250
251 $node_publisher->wait_for_catchup('tap_sub');
252
253 # Check the data on subscriber
254 my $result = $node_subscriber->safe_psql(
255 'postgres', qq(
256 SET timezone = '+2';
257 SELECT a, b FROM tst_one_array ORDER BY a;
258 SELECT a, b, c, d FROM tst_arrays ORDER BY a;
259 SELECT a, b FROM tst_one_enum ORDER BY a;
260 SELECT a, b FROM tst_enums ORDER BY a;
261 SELECT a, b FROM tst_one_comp ORDER BY a;
262 SELECT a, b FROM tst_comps ORDER BY a;
263 SELECT a, b FROM tst_comp_enum ORDER BY a;
264 SELECT a, b FROM tst_comp_enum_array ORDER BY a;
265 SELECT a, b FROM tst_comp_one_enum_array ORDER BY a;
266 SELECT a, b FROM tst_comp_enum_what ORDER BY a;
267 SELECT a, b FROM tst_comp_mix_array ORDER BY a;
268 SELECT a, b FROM tst_range ORDER BY a;
269 SELECT a, b, c FROM tst_range_array ORDER BY a;
270 SELECT a, b FROM tst_hstore ORDER BY a;
271 ));
272
273 is( $result, '1|{1,2,3}
274 2|{2,3,1}
275 3|{3,2,1}
276 4|{4,3,2}
277 5|{5,NULL,3}
278 {1,2,3}|{a,b,c}|{1.1,2.2,3.3}|{"1 day","2 days","3 days"}
279 {2,3,1}|{b,c,a}|{2.2,3.3,1.1}|{00:02:00,00:03:00,00:01:00}
280 {3,1,2}|{c,a,b}|{3.3,1.1,2.2}|{"3 years","1 year","2 years"}
281 {4,1,2}|{d,a,b}|{4.4,1.1,2.2}|{"4 years","1 year","2 years"}
282 {5,NULL,NULL}|{e,NULL,b}|{5.5,1.1,NULL}|{"5 years",NULL,NULL}
283 1|a
284 2|b
285 3|c
286 4|d
287 5|
288 a|{b,c}
289 b|{c,a}
290 c|{b,a}
291 d|{c,b}
292 e|{d,NULL}
293 1|(1,a,1)
294 2|(2,b,2)
295 3|(3,c,3)
296 4|(4,d,4)
297 5|(,,5)
298 (1,a,1)|{"(1,a,1)"}
299 (2,b,2)|{"(2,b,2)"}
300 (3,c,3)|{"(3,c,3)"}
301 (4,d,4)|{"(4,d,3)"}
302 (5,e,)|{NULL,"(5,,5)"}
303 1|(1,a,1)
304 2|(2,b,2)
305 3|(3,c,3)
306 4|(4,d,4)
307 5|(,e,)
308 (1,a,1)|{"(1,a,1)"}
309 (2,b,2)|{"(2,b,2)"}
310 (3,c,3)|{"(3,c,3)"}
311 (4,d,3)|{"(3,d,3)"}
312 (5,e,3)|{"(3,e,3)",NULL}
313 1|(1,"{a,b,c}",1)
314 2|(2,"{a,b,c}",2)
315 3|(3,"{a,b,c}",3)
316 4|(4,"{c,b,d}",4)
317 5|(5,"{NULL,e,NULL}",5)
318 (1,"{a,b,c}",1)|{"(1,\"{a,b,c}\",1)"}
319 (2,"{b,c,a}",2)|{"(2,\"{b,c,a}\",1)"}
320 (3,"{c,a,b}",1)|{"(3,\"{c,a,b}\",1)"}
321 (4,"{c,b,d}",4)|{"(4,\"{c,b,d}\",4)"}
322 (5,"{c,NULL,b}",)|{"(5,\"{c,e,b}\",1)"}
323 ("(1,a,1)","{""(1,a,1)"",""(2,b,2)""}",a,"{a,b,NULL,c}")|{"(\"(1,a,1)\",\"{\"\"(1,a,1)\"\",\"\"(2,b,2)\"\",NULL}\",a,\"{a,b,c}\")"}
324 1|[1,11)
325 2|[2,21)
326 3|[3,31)
327 4|[4,41)
328 5|[5,51)
329 1|["2014-08-04 00:00:00+02",infinity)|{"[1,3)","[10,21)"}
330 2|["2014-08-02 00:00:00+02","2014-08-04 00:00:00+02")|{"[2,4)","[20,31)"}
331 3|["2014-08-01 00:00:00+02","2014-08-04 00:00:00+02")|{"[3,5)"}
332 4|["2014-07-31 00:00:00+02","2014-08-04 00:00:00+02")|{"[4,6)",NULL,"[40,51)"}
333 5||
334 1|"a"=>"1"
335 2|"zzz"=>"foo"
336 3|"123"=>"321"
337 4|"yellow horse"=>"moaned"',
338 'check replicated inserts on subscriber');
339
340 # Run batch of updates
341 $node_publisher->safe_psql(
342 'postgres', qq(
343 UPDATE tst_one_array SET b = '{4, 5, 6}' WHERE a = 1;
344 UPDATE tst_one_array SET b = '{4, 5, 6, 1}' WHERE a > 3;
345 UPDATE tst_arrays SET b = '{"1a", "2b", "3c"}', c = '{1.0, 2.0, 3.0}', d = '{"1 day 1 second", "2 days 2 seconds", "3 days 3 second"}' WHERE a = '{1, 2, 3}';
346 UPDATE tst_arrays SET b = '{"c", "d", "e"}', c = '{3.0, 4.0, 5.0}', d = '{"3 day 1 second", "4 days 2 seconds", "5 days 3 second"}' WHERE a[1] > 3;
347 UPDATE tst_one_enum SET b = 'c' WHERE a = 1;
348 UPDATE tst_one_enum SET b = NULL WHERE a > 3;
349 UPDATE tst_enums SET b = '{e, NULL}' WHERE a = 'a';
350 UPDATE tst_enums SET b = '{e, d}' WHERE a > 'c';
351 UPDATE tst_one_comp SET b = ROW(1.0, 'A', 1) WHERE a = 1;
352 UPDATE tst_one_comp SET b = ROW(NULL, 'x', -1) WHERE a > 3;
353 UPDATE tst_comps SET b = ARRAY[ROW(9, 'x', -1)::tst_comp_basic_t] WHERE (a).a = 1.0;
354 UPDATE tst_comps SET b = ARRAY[NULL, ROW(9, 'x', NULL)::tst_comp_basic_t] WHERE (a).a > 3.9;
355 UPDATE tst_comp_enum SET b = ROW(1.0, NULL, NULL) WHERE a = 1;
356 UPDATE tst_comp_enum SET b = ROW(4.0, 'd', 44) WHERE a > 3;
357 UPDATE tst_comp_enum_array SET b = ARRAY[NULL, ROW(3, 'd', 3)::tst_comp_enum_t] WHERE a = ROW(1.0, 'a', 1)::tst_comp_enum_t;
358 UPDATE tst_comp_enum_array SET b = ARRAY[ROW(1, 'a', 1)::tst_comp_enum_t, ROW(2, 'b', 2)::tst_comp_enum_t] WHERE (a).a > 3;
359 UPDATE tst_comp_one_enum_array SET b = ROW(1.0, '{a, e, c}', NULL) WHERE a = 1;
360 UPDATE tst_comp_one_enum_array SET b = ROW(4.0, '{c, b, d}', 4) WHERE a > 3;
361 UPDATE tst_comp_enum_what SET b = ARRAY[NULL, ROW(1, '{a, b, c}', 1)::tst_comp_enum_array_t, ROW(NULL, '{a, e, c}', 2)::tst_comp_enum_array_t] WHERE (a).a = 1;
362 UPDATE tst_comp_enum_what SET b = ARRAY[ROW(5, '{a, b, c}', 5)::tst_comp_enum_array_t] WHERE (a).a > 3;
363 UPDATE tst_comp_mix_array SET b[2] = NULL WHERE ((a).a).a = 1;
364 UPDATE tst_range SET b = '[100, 1000]' WHERE a = 1;
365 UPDATE tst_range SET b = '(1, 90)' WHERE a > 3;
366 UPDATE tst_range_array SET c = '{"[100, 1000]"}' WHERE a = 1;
367 UPDATE tst_range_array SET b = tstzrange('Mon Aug 04 00:00:00 2014 CEST'::timestamptz, 'infinity'), c = '{NULL, "[11,9999999]"}' WHERE a > 3;
368 UPDATE tst_hstore SET b = '"updated"=>"value"' WHERE a < 3;
369 UPDATE tst_hstore SET b = '"also"=>"updated"' WHERE a = 3;
370 ));
371
372 $node_publisher->wait_for_catchup('tap_sub');
373
374 # Check the data on subscriber
375 $result = $node_subscriber->safe_psql(
376 'postgres', qq(
377 SET timezone = '+2';
378 SELECT a, b FROM tst_one_array ORDER BY a;
379 SELECT a, b, c, d FROM tst_arrays ORDER BY a;
380 SELECT a, b FROM tst_one_enum ORDER BY a;
381 SELECT a, b FROM tst_enums ORDER BY a;
382 SELECT a, b FROM tst_one_comp ORDER BY a;
383 SELECT a, b FROM tst_comps ORDER BY a;
384 SELECT a, b FROM tst_comp_enum ORDER BY a;
385 SELECT a, b FROM tst_comp_enum_array ORDER BY a;
386 SELECT a, b FROM tst_comp_one_enum_array ORDER BY a;
387 SELECT a, b FROM tst_comp_enum_what ORDER BY a;
388 SELECT a, b FROM tst_comp_mix_array ORDER BY a;
389 SELECT a, b FROM tst_range ORDER BY a;
390 SELECT a, b, c FROM tst_range_array ORDER BY a;
391 SELECT a, b FROM tst_hstore ORDER BY a;
392 ));
393
394 is( $result, '1|{4,5,6}
395 2|{2,3,1}
396 3|{3,2,1}
397 4|{4,5,6,1}
398 5|{4,5,6,1}
399 {1,2,3}|{1a,2b,3c}|{1,2,3}|{"1 day 00:00:01","2 days 00:00:02","3 days 00:00:03"}
400 {2,3,1}|{b,c,a}|{2.2,3.3,1.1}|{00:02:00,00:03:00,00:01:00}
401 {3,1,2}|{c,a,b}|{3.3,1.1,2.2}|{"3 years","1 year","2 years"}
402 {4,1,2}|{c,d,e}|{3,4,5}|{"3 days 00:00:01","4 days 00:00:02","5 days 00:00:03"}
403 {5,NULL,NULL}|{c,d,e}|{3,4,5}|{"3 days 00:00:01","4 days 00:00:02","5 days 00:00:03"}
404 1|c
405 2|b
406 3|c
407 4|
408 5|
409 a|{e,NULL}
410 b|{c,a}
411 c|{b,a}
412 d|{e,d}
413 e|{e,d}
414 1|(1,A,1)
415 2|(2,b,2)
416 3|(3,c,3)
417 4|(,x,-1)
418 5|(,x,-1)
419 (1,a,1)|{"(9,x,-1)"}
420 (2,b,2)|{"(2,b,2)"}
421 (3,c,3)|{"(3,c,3)"}
422 (4,d,4)|{NULL,"(9,x,)"}
423 (5,e,)|{NULL,"(9,x,)"}
424 1|(1,,)
425 2|(2,b,2)
426 3|(3,c,3)
427 4|(4,d,44)
428 5|(4,d,44)
429 (1,a,1)|{NULL,"(3,d,3)"}
430 (2,b,2)|{"(2,b,2)"}
431 (3,c,3)|{"(3,c,3)"}
432 (4,d,3)|{"(1,a,1)","(2,b,2)"}
433 (5,e,3)|{"(1,a,1)","(2,b,2)"}
434 1|(1,"{a,e,c}",)
435 2|(2,"{a,b,c}",2)
436 3|(3,"{a,b,c}",3)
437 4|(4,"{c,b,d}",4)
438 5|(4,"{c,b,d}",4)
439 (1,"{a,b,c}",1)|{NULL,"(1,\"{a,b,c}\",1)","(,\"{a,e,c}\",2)"}
440 (2,"{b,c,a}",2)|{"(2,\"{b,c,a}\",1)"}
441 (3,"{c,a,b}",1)|{"(3,\"{c,a,b}\",1)"}
442 (4,"{c,b,d}",4)|{"(5,\"{a,b,c}\",5)"}
443 (5,"{c,NULL,b}",)|{"(5,\"{a,b,c}\",5)"}
444 ("(1,a,1)","{""(1,a,1)"",""(2,b,2)""}",a,"{a,b,NULL,c}")|{"(\"(1,a,1)\",\"{\"\"(1,a,1)\"\",\"\"(2,b,2)\"\",NULL}\",a,\"{a,b,c}\")",NULL}
445 1|[100,1001)
446 2|[2,21)
447 3|[3,31)
448 4|[2,90)
449 5|[2,90)
450 1|["2014-08-04 00:00:00+02",infinity)|{"[100,1001)"}
451 2|["2014-08-02 00:00:00+02","2014-08-04 00:00:00+02")|{"[2,4)","[20,31)"}
452 3|["2014-08-01 00:00:00+02","2014-08-04 00:00:00+02")|{"[3,5)"}
453 4|["2014-08-04 00:00:00+02",infinity)|{NULL,"[11,10000000)"}
454 5|["2014-08-04 00:00:00+02",infinity)|{NULL,"[11,10000000)"}
455 1|"updated"=>"value"
456 2|"updated"=>"value"
457 3|"also"=>"updated"
458 4|"yellow horse"=>"moaned"',
459 'check replicated updates on subscriber');
460
461 # Run batch of deletes
462 $node_publisher->safe_psql(
463 'postgres', qq(
464 DELETE FROM tst_one_array WHERE a = 1;
465 DELETE FROM tst_one_array WHERE b = '{2, 3, 1}';
466 DELETE FROM tst_arrays WHERE a = '{1, 2, 3}';
467 DELETE FROM tst_arrays WHERE a[1] = 2;
468 DELETE FROM tst_one_enum WHERE a = 1;
469 DELETE FROM tst_one_enum WHERE b = 'b';
470 DELETE FROM tst_enums WHERE a = 'a';
471 DELETE FROM tst_enums WHERE b[1] = 'b';
472 DELETE FROM tst_one_comp WHERE a = 1;
473 DELETE FROM tst_one_comp WHERE (b).a = 2.0;
474 DELETE FROM tst_comps WHERE (a).b = 'a';
475 DELETE FROM tst_comps WHERE ROW(3, 'c', 3)::tst_comp_basic_t = ANY(b);
476 DELETE FROM tst_comp_enum WHERE a = 1;
477 DELETE FROM tst_comp_enum WHERE (b).a = 2.0;
478 DELETE FROM tst_comp_enum_array WHERE a = ROW(1.0, 'a', 1)::tst_comp_enum_t;
479 DELETE FROM tst_comp_enum_array WHERE ROW(3, 'c', 3)::tst_comp_enum_t = ANY(b);
480 DELETE FROM tst_comp_one_enum_array WHERE a = 1;
481 DELETE FROM tst_comp_one_enum_array WHERE 'a' = ANY((b).b);
482 DELETE FROM tst_comp_enum_what WHERE (a).a = 1;
483 DELETE FROM tst_comp_enum_what WHERE (b[1]).b = '{c, a, b}';
484 DELETE FROM tst_comp_mix_array WHERE ((a).a).a = 1;
485 DELETE FROM tst_range WHERE a = 1;
486 DELETE FROM tst_range WHERE '[10,20]' && b;
487 DELETE FROM tst_range_array WHERE a = 1;
488 DELETE FROM tst_range_array WHERE tstzrange('Mon Aug 04 00:00:00 2014 CEST'::timestamptz, 'Mon Aug 05 00:00:00 2014 CEST'::timestamptz) && b;
489 DELETE FROM tst_hstore WHERE a = 1;
490 ));
491
492 $node_publisher->wait_for_catchup('tap_sub');
493
494 # Check the data on subscriber
495 $result = $node_subscriber->safe_psql(
496 'postgres', qq(
497 SET timezone = '+2';
498 SELECT a, b FROM tst_one_array ORDER BY a;
499 SELECT a, b, c, d FROM tst_arrays ORDER BY a;
500 SELECT a, b FROM tst_one_enum ORDER BY a;
501 SELECT a, b FROM tst_enums ORDER BY a;
502 SELECT a, b FROM tst_one_comp ORDER BY a;
503 SELECT a, b FROM tst_comps ORDER BY a;
504 SELECT a, b FROM tst_comp_enum ORDER BY a;
505 SELECT a, b FROM tst_comp_enum_array ORDER BY a;
506 SELECT a, b FROM tst_comp_one_enum_array ORDER BY a;
507 SELECT a, b FROM tst_comp_enum_what ORDER BY a;
508 SELECT a, b FROM tst_comp_mix_array ORDER BY a;
509 SELECT a, b FROM tst_range ORDER BY a;
510 SELECT a, b, c FROM tst_range_array ORDER BY a;
511 SELECT a, b FROM tst_hstore ORDER BY a;
512 ));
513
514 is( $result, '3|{3,2,1}
515 4|{4,5,6,1}
516 5|{4,5,6,1}
517 {3,1,2}|{c,a,b}|{3.3,1.1,2.2}|{"3 years","1 year","2 years"}
518 {4,1,2}|{c,d,e}|{3,4,5}|{"3 days 00:00:01","4 days 00:00:02","5 days 00:00:03"}
519 {5,NULL,NULL}|{c,d,e}|{3,4,5}|{"3 days 00:00:01","4 days 00:00:02","5 days 00:00:03"}
520 3|c
521 4|
522 5|
523 b|{c,a}
524 d|{e,d}
525 e|{e,d}
526 3|(3,c,3)
527 4|(,x,-1)
528 5|(,x,-1)
529 (2,b,2)|{"(2,b,2)"}
530 (4,d,4)|{NULL,"(9,x,)"}
531 (5,e,)|{NULL,"(9,x,)"}
532 3|(3,c,3)
533 4|(4,d,44)
534 5|(4,d,44)
535 (2,b,2)|{"(2,b,2)"}
536 (4,d,3)|{"(1,a,1)","(2,b,2)"}
537 (5,e,3)|{"(1,a,1)","(2,b,2)"}
538 4|(4,"{c,b,d}",4)
539 5|(4,"{c,b,d}",4)
540 (2,"{b,c,a}",2)|{"(2,\"{b,c,a}\",1)"}
541 (4,"{c,b,d}",4)|{"(5,\"{a,b,c}\",5)"}
542 (5,"{c,NULL,b}",)|{"(5,\"{a,b,c}\",5)"}
543 2|["2014-08-02 00:00:00+02","2014-08-04 00:00:00+02")|{"[2,4)","[20,31)"}
544 3|["2014-08-01 00:00:00+02","2014-08-04 00:00:00+02")|{"[3,5)"}
545 2|"updated"=>"value"
546 3|"also"=>"updated"
547 4|"yellow horse"=>"moaned"',
548 'check replicated deletes on subscriber');
549
550 # Test a domain with a constraint backed by a SQL-language function,
551 # which needs an active snapshot in order to operate.
552 $node_publisher->safe_psql('postgres',
553 "INSERT INTO tst_dom_constr VALUES (11)");
554
555 $node_publisher->wait_for_catchup('tap_sub');
556
557 $result =
558 $node_subscriber->safe_psql('postgres',
559 "SELECT sum(a) FROM tst_dom_constr");
560 is($result, '21', 'sql-function constraint on domain');
561
562 $node_subscriber->stop('fast');
563 $node_publisher->stop('fast');
564
565 done_testing();