Migrate the former contrib/txid module into core. This will make it easier
[PostgreSQL.git] / src / test / regress / sql / txid.sql
blobecae10e024d3961cab062698e421213293ea856b
1 -- txid_snapshot data type and related functions
3 -- i/o
4 select '12:13:'::txid_snapshot;
5 select '12:18:14,16'::txid_snapshot;
7 -- errors
8 select '31:12:'::txid_snapshot;
9 select '0:1:'::txid_snapshot;
10 select '12:13:0'::txid_snapshot;
11 select '12:16:14,13'::txid_snapshot;
12 select '12:16:14,14'::txid_snapshot;
14 create temp table snapshot_test (
15         nr      integer,
16         snap    txid_snapshot
19 insert into snapshot_test values (1, '12:13:');
20 insert into snapshot_test values (2, '12:20:13,15,18');
21 insert into snapshot_test values (3, '100001:100009:100005,100007,100008');
22 insert into snapshot_test values (4, '100:150:101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131');
23 select snap from snapshot_test order by nr;
25 select  txid_snapshot_xmin(snap),
26         txid_snapshot_xmax(snap),
27         txid_snapshot_xip(snap)
28 from snapshot_test order by nr;
30 select id, txid_visible_in_snapshot(id, snap)
31 from snapshot_test, generate_series(11, 21) id
32 where nr = 2;
34 -- test bsearch
35 select id, txid_visible_in_snapshot(id, snap)
36 from snapshot_test, generate_series(90, 160) id
37 where nr = 4;
39 -- test current values also
40 select txid_current() >= txid_snapshot_xmin(txid_current_snapshot());
42 -- we can't assume current is always less than xmax, however
44 select txid_visible_in_snapshot(txid_current(), txid_current_snapshot());
46 -- test 64bitness
48 select txid_snapshot '1000100010001000:1000100010001100:1000100010001012,1000100010001013';
49 select txid_visible_in_snapshot('1000100010001012', '1000100010001000:1000100010001100:1000100010001012,1000100010001013');
50 select txid_visible_in_snapshot('1000100010001015', '1000100010001000:1000100010001100:1000100010001012,1000100010001013');
52 -- test 64bit overflow
53 SELECT txid_snapshot '1:9223372036854775807:3';
54 SELECT txid_snapshot '1:9223372036854775808:3';