10 create unique index tttest_idx on tttest (price_id,price_off);
11 alter table tttest add column q1 text;
12 alter table tttest add column q2 int;
13 alter table tttest drop column q1;
15 create trigger timetravel
16 before insert or delete or update on tttest
19 timetravel (price_on, price_off);
21 insert into tttest values (1, 1, null, null);
22 insert into tttest(price_id, price_val) values (2, 2);
23 insert into tttest(price_id, price_val,price_off) values (3, 3, 'infinity');
25 insert into tttest(price_id, price_val,price_off) values (4, 4,
26 abstime('now'::timestamp - '100 days'::interval));
27 insert into tttest(price_id, price_val,price_on) values (3, 3, 'infinity'); -- duplicate key
30 delete from tttest where price_id = 2;
35 select * from tttest where price_off = 'infinity';
37 -- change price for price_id == 3
38 update tttest set price_val = 30 where price_id = 3;
41 -- now we want to change price_id from 3 to 5 in ALL tuples
42 -- but this gets us not what we need
43 update tttest set price_id = 5 where price_id = 3;
46 -- restore data as before last update:
47 select set_timetravel('tttest', 0); -- turn TT OFF!
49 select get_timetravel('tttest'); -- check status
51 delete from tttest where price_id = 5;
52 update tttest set price_off = 'infinity' where price_val = 30;
55 -- and try change price_id now!
56 update tttest set price_id = 5 where price_id = 3;
58 -- isn't it what we need ?
60 select set_timetravel('tttest', 1); -- turn TT ON!
62 select get_timetravel('tttest'); -- check status
64 -- we want to correct some date
65 update tttest set price_on = 'Jan-01-1990 00:00:01' where price_id = 5 and
66 price_off <> 'infinity';
67 -- but this doesn't work
70 select set_timetravel('tttest', 0); -- turn TT OFF!
72 select get_timetravel('tttest'); -- check status
74 update tttest set price_on = '01-Jan-1990 00:00:01' where price_id = 5 and
75 price_off <> 'infinity';
77 -- isn't it what we need ?
79 -- get price for price_id == 5 as it was '10-Jan-1990'
80 select * from tttest where price_id = 5 and
81 price_on <= '10-Jan-1990' and price_off > '10-Jan-1990';