1 -- tests for functions related to TID handling
2 CREATE TABLE tid_tab (a int);
3 -- min() and max() for TIDs
4 INSERT INTO tid_tab VALUES (1), (2);
5 SELECT min(ctid) FROM tid_tab;
11 SELECT max(ctid) FROM tid_tab;
18 -- Tests for currtid2() with various relation kinds
20 CREATE MATERIALIZED VIEW tid_matview AS SELECT a FROM tid_tab;
21 SELECT currtid2('tid_matview'::text, '(0,1)'::tid); -- fails
22 ERROR: tid (0, 1) is not valid for relation "tid_matview"
23 INSERT INTO tid_tab VALUES (1);
24 REFRESH MATERIALIZED VIEW tid_matview;
25 SELECT currtid2('tid_matview'::text, '(0,1)'::tid); -- ok
31 DROP MATERIALIZED VIEW tid_matview;
34 CREATE SEQUENCE tid_seq;
35 SELECT currtid2('tid_seq'::text, '(0,1)'::tid); -- ok
41 DROP SEQUENCE tid_seq;
42 -- Index, fails with incorrect relation type
43 CREATE INDEX tid_ind ON tid_tab(a);
44 SELECT currtid2('tid_ind'::text, '(0,1)'::tid); -- fails
45 ERROR: "tid_ind" is an index
47 -- Partitioned table, no storage
48 CREATE TABLE tid_part (a int) PARTITION BY RANGE (a);
49 SELECT currtid2('tid_part'::text, '(0,1)'::tid); -- fails
50 ERROR: cannot look at latest visible tid for relation "public.tid_part"
53 -- ctid not defined in the view
54 CREATE VIEW tid_view_no_ctid AS SELECT a FROM tid_tab;
55 SELECT currtid2('tid_view_no_ctid'::text, '(0,1)'::tid); -- fails
56 ERROR: currtid cannot handle views with no CTID
57 DROP VIEW tid_view_no_ctid;
58 -- ctid fetched directly from the source table.
59 CREATE VIEW tid_view_with_ctid AS SELECT ctid, a FROM tid_tab;
60 SELECT currtid2('tid_view_with_ctid'::text, '(0,1)'::tid); -- fails
61 ERROR: tid (0, 1) is not valid for relation "tid_tab"
62 INSERT INTO tid_tab VALUES (1);
63 SELECT currtid2('tid_view_with_ctid'::text, '(0,1)'::tid); -- ok
69 DROP VIEW tid_view_with_ctid;
71 -- ctid attribute with incorrect data type
72 CREATE VIEW tid_view_fake_ctid AS SELECT 1 AS ctid, 2 AS a;
73 SELECT currtid2('tid_view_fake_ctid'::text, '(0,1)'::tid); -- fails
74 ERROR: ctid isn't of type TID
75 DROP VIEW tid_view_fake_ctid;
76 DROP TABLE tid_tab CASCADE;