mirror of
https://github.com/postgres/postgres.git
synced 2025-04-25 21:42:33 +03:00
Timetravel tests.
This commit is contained in:
parent
76271543ae
commit
c13454edc2
@ -159,3 +159,122 @@ count
|
||||
(1 row)
|
||||
|
||||
QUERY: DROP TABLE dup17;
|
||||
QUERY: create sequence ttdummy_seq increment 10 start 0 minvalue 0;
|
||||
QUERY: create table tttest (
|
||||
price_id int4,
|
||||
price_val int4,
|
||||
price_on int4 default nextval('ttdummy_seq'),
|
||||
price_off int4 default 999999
|
||||
);
|
||||
QUERY: insert into tttest values (1, 1, null, null);
|
||||
QUERY: insert into tttest values (2, 2, null, null);
|
||||
QUERY: insert into tttest values (3, 3, null, null);
|
||||
QUERY: create trigger ttdummy
|
||||
before delete or update on tttest
|
||||
for each row
|
||||
execute procedure
|
||||
ttdummy (price_on, price_off);
|
||||
QUERY: select * from tttest;
|
||||
price_id|price_val|price_on|price_off
|
||||
--------+---------+--------+---------
|
||||
1| 1| 0| 999999
|
||||
2| 2| 10| 999999
|
||||
3| 3| 20| 999999
|
||||
(3 rows)
|
||||
|
||||
QUERY: delete from tttest where price_id = 2;
|
||||
QUERY: select * from tttest;
|
||||
price_id|price_val|price_on|price_off
|
||||
--------+---------+--------+---------
|
||||
1| 1| 0| 999999
|
||||
3| 3| 20| 999999
|
||||
2| 2| 10| 30
|
||||
(3 rows)
|
||||
|
||||
QUERY: select * from tttest where price_off = 999999;
|
||||
price_id|price_val|price_on|price_off
|
||||
--------+---------+--------+---------
|
||||
1| 1| 0| 999999
|
||||
3| 3| 20| 999999
|
||||
(2 rows)
|
||||
|
||||
QUERY: update tttest set price_val = 30 where price_id = 3;
|
||||
QUERY: select * from tttest;
|
||||
price_id|price_val|price_on|price_off
|
||||
--------+---------+--------+---------
|
||||
1| 1| 0| 999999
|
||||
2| 2| 10| 30
|
||||
3| 30| 40| 999999
|
||||
3| 3| 20| 40
|
||||
(4 rows)
|
||||
|
||||
QUERY: update tttest set price_id = 5 where price_id = 3;
|
||||
QUERY: select * from tttest;
|
||||
price_id|price_val|price_on|price_off
|
||||
--------+---------+--------+---------
|
||||
1| 1| 0| 999999
|
||||
2| 2| 10| 30
|
||||
3| 3| 20| 40
|
||||
5| 30| 50| 999999
|
||||
3| 30| 40| 50
|
||||
(5 rows)
|
||||
|
||||
QUERY: select set_ttdummy(0);
|
||||
set_ttdummy
|
||||
-----------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
QUERY: delete from tttest where price_id = 5;
|
||||
QUERY: update tttest set price_off = 999999 where price_val = 30;
|
||||
QUERY: select * from tttest;
|
||||
price_id|price_val|price_on|price_off
|
||||
--------+---------+--------+---------
|
||||
1| 1| 0| 999999
|
||||
2| 2| 10| 30
|
||||
3| 3| 20| 40
|
||||
3| 30| 40| 999999
|
||||
(4 rows)
|
||||
|
||||
QUERY: update tttest set price_id = 5 where price_id = 3;
|
||||
QUERY: select * from tttest;
|
||||
price_id|price_val|price_on|price_off
|
||||
--------+---------+--------+---------
|
||||
1| 1| 0| 999999
|
||||
2| 2| 10| 30
|
||||
5| 3| 20| 40
|
||||
5| 30| 40| 999999
|
||||
(4 rows)
|
||||
|
||||
QUERY: select set_ttdummy(1);
|
||||
set_ttdummy
|
||||
-----------
|
||||
0
|
||||
(1 row)
|
||||
|
||||
QUERY: update tttest set price_on = -1 where price_id = 1;
|
||||
WARN:ttdummy (tttest): you can't change price_on and/or price_off columns (use set_ttdummy)
|
||||
QUERY: select set_ttdummy(0);
|
||||
set_ttdummy
|
||||
-----------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
QUERY: update tttest set price_on = -1 where price_id = 1;
|
||||
QUERY: select * from tttest;
|
||||
price_id|price_val|price_on|price_off
|
||||
--------+---------+--------+---------
|
||||
2| 2| 10| 30
|
||||
5| 3| 20| 40
|
||||
5| 30| 40| 999999
|
||||
1| 1| -1| 999999
|
||||
(4 rows)
|
||||
|
||||
QUERY: select * from tttest where price_on <= 25 and price_off > 25 and price_id = 5;
|
||||
price_id|price_val|price_on|price_off
|
||||
--------+---------+--------+---------
|
||||
5| 3| 20| 40
|
||||
(1 row)
|
||||
|
||||
QUERY: drop table tttest;
|
||||
QUERY: drop sequence ttdummy_seq;
|
||||
|
@ -30,3 +30,15 @@ CREATE FUNCTION funny_dup17 ()
|
||||
AS '_OBJWD_/regress_DLSUFFIX_'
|
||||
LANGUAGE 'c'
|
||||
;
|
||||
|
||||
CREATE FUNCTION ttdummy ()
|
||||
RETURNS opaque
|
||||
AS '_OBJWD_/regress_DLSUFFIX_'
|
||||
LANGUAGE 'c'
|
||||
;
|
||||
|
||||
CREATE FUNCTION set_ttdummy (int4)
|
||||
RETURNS int4
|
||||
AS '_OBJWD_/regress_DLSUFFIX_'
|
||||
LANGUAGE 'c'
|
||||
;
|
||||
|
@ -9,16 +9,26 @@ QUERY: CREATE FUNCTION widget_out(opaque)
|
||||
LANGUAGE 'c';
|
||||
QUERY: CREATE FUNCTION check_primary_key ()
|
||||
RETURNS opaque
|
||||
AS '_OBJWD_/../../../contrib/spi/refint.so'
|
||||
AS '_OBJWD_/../../../contrib/spi/refint_DLSUFFIX_'
|
||||
LANGUAGE 'c'
|
||||
;
|
||||
QUERY: CREATE FUNCTION check_foreign_key ()
|
||||
RETURNS opaque
|
||||
AS '_OBJWD_/../../../contrib/spi/refint.so'
|
||||
AS '_OBJWD_/../../../contrib/spi/refint_DLSUFFIX_'
|
||||
LANGUAGE 'c'
|
||||
;
|
||||
QUERY: CREATE FUNCTION funny_dup17 ()
|
||||
RETURNS opaque
|
||||
AS '_OBJWD_/regress.so'
|
||||
AS '_OBJWD_/regress_DLSUFFIX_'
|
||||
LANGUAGE 'c'
|
||||
;
|
||||
QUERY: CREATE FUNCTION ttdummy ()
|
||||
RETURNS opaque
|
||||
AS '_OBJWD_/regress_DLSUFFIX_'
|
||||
LANGUAGE 'c'
|
||||
;
|
||||
QUERY: CREATE FUNCTION set_ttdummy (int4)
|
||||
RETURNS int4
|
||||
AS '_OBJWD_/regress_DLSUFFIX_'
|
||||
LANGUAGE 'c'
|
||||
;
|
||||
|
@ -116,3 +116,68 @@ insert into dup17 values (13);
|
||||
select count(*) from dup17 where x = 13;
|
||||
|
||||
DROP TABLE dup17;
|
||||
|
||||
create sequence ttdummy_seq increment 10 start 0 minvalue 0;
|
||||
|
||||
create table tttest (
|
||||
price_id int4,
|
||||
price_val int4,
|
||||
price_on int4 default nextval('ttdummy_seq'),
|
||||
price_off int4 default 999999
|
||||
);
|
||||
|
||||
insert into tttest values (1, 1, null, null);
|
||||
insert into tttest values (2, 2, null, null);
|
||||
insert into tttest values (3, 3, null, null);
|
||||
|
||||
create trigger ttdummy
|
||||
before delete or update on tttest
|
||||
for each row
|
||||
execute procedure
|
||||
ttdummy (price_on, price_off);
|
||||
|
||||
select * from tttest;
|
||||
delete from tttest where price_id = 2;
|
||||
select * from tttest;
|
||||
-- what do we see ?
|
||||
|
||||
-- get current prices
|
||||
select * from tttest where price_off = 999999;
|
||||
|
||||
-- change price for price_id == 3
|
||||
update tttest set price_val = 30 where price_id = 3;
|
||||
select * from tttest;
|
||||
|
||||
-- now we want to change pric_id in ALL tuples
|
||||
-- this gets us not what we need
|
||||
update tttest set price_id = 5 where price_id = 3;
|
||||
select * from tttest;
|
||||
|
||||
-- restore data as before last update:
|
||||
select set_ttdummy(0);
|
||||
delete from tttest where price_id = 5;
|
||||
update tttest set price_off = 999999 where price_val = 30;
|
||||
select * from tttest;
|
||||
|
||||
-- and try change price_id now!
|
||||
update tttest set price_id = 5 where price_id = 3;
|
||||
select * from tttest;
|
||||
-- isn't it what we need ?
|
||||
|
||||
select set_ttdummy(1);
|
||||
|
||||
-- we want to correct some "date"
|
||||
update tttest set price_on = -1 where price_id = 1;
|
||||
-- but this doesn't work
|
||||
|
||||
-- try in this way
|
||||
select set_ttdummy(0);
|
||||
update tttest set price_on = -1 where price_id = 1;
|
||||
select * from tttest;
|
||||
-- isn't it what we need ?
|
||||
|
||||
-- get price for price_id == 5 as it was @ "date" 25
|
||||
select * from tttest where price_on <= 25 and price_off > 25 and price_id = 5;
|
||||
|
||||
drop table tttest;
|
||||
drop sequence ttdummy_seq;
|
||||
|
Loading…
x
Reference in New Issue
Block a user