1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
---
--- pgcopydb test/cdc/dml.sql
---
--- This file implements DML changes in the pagila database.
\set customerid1 291
\set customerid2 292
\set staffid1 1
\set staffid2 2
\set inventoryid1 371
\set inventoryid2 1097
begin;
with r as
(
insert into rental(rental_date, inventory_id, customer_id, staff_id, last_update)
select '2022-06-01', :inventoryid1, :customerid1, :staffid1, '2022-06-01'
returning rental_id, customer_id, staff_id
)
insert into payment(customer_id, staff_id, rental_id, amount, payment_date)
select customer_id, staff_id, rental_id, 5.99, '2022-06-01'
from r;
commit;
-- update 10 rows in a single UPDATE command
update public.payment set amount = 11.95 where amount = 11.99;
begin;
delete from payment
using rental
where rental.rental_id = payment.rental_id
and rental.last_update = '2022-06-01';
delete from rental where rental.last_update = '2022-06-01';
commit;
--
-- update the payments back to their original values
--
begin;
update public.payment set amount = 11.99 where amount = 11.95;
commit;
--
-- Test "is null" transformation in change data capture.
--
begin;
-- Disable triggers to prevent automatic refresh of 'last_updated' attribute
-- when modifying rows in the address table.
set session_replication_role = replica;
delete from address where city_id = 300 and address2 is null;
update address set postal_code = '751007' where phone = '6172235589' and address2 is null;
commit;
--
-- Test generated columns insert, update, and delete
--
begin;
insert into generated_column_test(id, name, email) values
(1, 'Tiger', 'tiger@wild.com'),
(2, 'Elephant', 'elephant@wild.com'),
(3, 'Cat', 'cat@home.net');
commit;
begin;
update generated_column_test set name = 'Lion'
where id = 1;
update generated_column_test set email='lion@wild.com'
where email = 'tiger@wild.com';
commit;
begin;
update generated_column_test set name = 'Kitten', email='kitten@home.com'
where id = 3;
commit;
begin;
delete from generated_column_test where id = 2;
commit;
|