3
3
use warnings;
4
4
use PostgresNode;
5
5
use TestLib;
6
- use Test::More tests => 4 ;
6
+ use Test::More tests => 6 ;
7
7
8
8
# Initialize publisher node
9
9
my $node_publisher = get_new_node(' publisher' );
@@ -88,14 +88,16 @@ BEGIN
88
88
ELSE
89
89
RETURN NULL;
90
90
END IF;
91
+ ELSIF (TG_OP = 'UPDATE') THEN
92
+ RETURN NULL;
91
93
ELSE
92
94
RAISE WARNING 'Unknown action';
93
95
RETURN NULL;
94
96
END IF;
95
97
END;
96
98
\$\$ LANGUAGE plpgsql;
97
99
CREATE TRIGGER filter_basic_dml_trg
98
- BEFORE INSERT ON tab_fk_ref
100
+ BEFORE INSERT OR UPDATE OF bid ON tab_fk_ref
99
101
FOR EACH ROW EXECUTE PROCEDURE filter_basic_dml_fn();
100
102
ALTER TABLE tab_fk_ref ENABLE REPLICA TRIGGER filter_basic_dml_trg;
101
103
} );
@@ -107,10 +109,34 @@ BEGIN
107
109
$node_publisher -> poll_query_until(' postgres' , $caughtup_query )
108
110
or die " Timed out while waiting for subscriber to catch up" ;
109
111
110
- # The row should be skipped on subscriber
112
+ # The trigger should cause the insert to be skipped on subscriber
113
+ $result = $node_subscriber -> safe_psql(' postgres' ,
114
+ " SELECT count(*), min(bid), max(bid) FROM tab_fk_ref;" );
115
+ is($result , qq( 2|1|2) , ' check replica insert trigger applied on subscriber' );
116
+
117
+ # Update data
118
+ $node_publisher -> safe_psql(' postgres' ,
119
+ " UPDATE tab_fk_ref SET bid = 2 WHERE bid = 1;" );
120
+
121
+ $node_publisher -> poll_query_until(' postgres' , $caughtup_query )
122
+ or die " Timed out while waiting for subscriber to catch up" ;
123
+
124
+ # The trigger should cause the update to be skipped on subscriber
111
125
$result = $node_subscriber -> safe_psql(' postgres' ,
112
126
" SELECT count(*), min(bid), max(bid) FROM tab_fk_ref;" );
113
- is($result , qq( 2|1|2) , ' check replica trigger applied on subscriber' );
127
+ is($result , qq( 2|1|2) , ' check replica update column trigger applied on subscriber' );
128
+
129
+ # Update on a column not specified in the trigger, but it will trigger
130
+ # anyway because logical replication ships all columns in an update.
131
+ $node_publisher -> safe_psql(' postgres' ,
132
+ " UPDATE tab_fk_ref SET id = 6 WHERE id = 1;" );
133
+
134
+ $node_publisher -> poll_query_until(' postgres' , $caughtup_query )
135
+ or die " Timed out while waiting for subscriber to catch up" ;
136
+
137
+ $result = $node_subscriber -> safe_psql(' postgres' ,
138
+ " SELECT count(*), min(id), max(id) FROM tab_fk_ref;" );
139
+ is($result , qq( 2|1|2) , ' check column trigger applied on even for other column' );
114
140
115
141
$node_subscriber -> stop(' fast' );
116
142
$node_publisher -> stop(' fast' );
0 commit comments