1 -- basic tests for the TID data type
5 '(-1,0)'::tid as tidm10,
6 '(4294967295,65535)'::tid as tidmax;
7 tid00 | tid01 | tidm10 | tidmax
8 -------+-------+----------------+--------------------
9 (0,0) | (0,1) | (4294967295,0) | (4294967295,65535)
12 SELECT '(4294967296,1)'::tid; -- error
13 ERROR: invalid input syntax for type tid: "(4294967296,1)"
14 LINE 1: SELECT '(4294967296,1)'::tid;
16 SELECT '(1,65536)'::tid; -- error
17 ERROR: invalid input syntax for type tid: "(1,65536)"
18 LINE 1: SELECT '(1,65536)'::tid;
20 -- Also try it with non-error-throwing API
21 SELECT pg_input_is_valid('(0)', 'tid');
27 SELECT * FROM pg_input_error_info('(0)', 'tid');
28 message | detail | hint | sql_error_code
29 ------------------------------------------+--------+------+----------------
30 invalid input syntax for type tid: "(0)" | | | 22P02
33 SELECT pg_input_is_valid('(0,-1)', 'tid');
39 SELECT * FROM pg_input_error_info('(0,-1)', 'tid');
40 message | detail | hint | sql_error_code
41 ---------------------------------------------+--------+------+----------------
42 invalid input syntax for type tid: "(0,-1)" | | | 22P02
45 -- tests for functions related to TID handling
46 CREATE TABLE tid_tab (a int);
47 -- min() and max() for TIDs
48 INSERT INTO tid_tab VALUES (1), (2);
49 SELECT min(ctid) FROM tid_tab;
55 SELECT max(ctid) FROM tid_tab;
62 -- Tests for currtid2() with various relation kinds
64 CREATE MATERIALIZED VIEW tid_matview AS SELECT a FROM tid_tab;
65 SELECT currtid2('tid_matview'::text, '(0,1)'::tid); -- fails
66 ERROR: tid (0, 1) is not valid for relation "tid_matview"
67 INSERT INTO tid_tab VALUES (1);
68 REFRESH MATERIALIZED VIEW tid_matview;
69 SELECT currtid2('tid_matview'::text, '(0,1)'::tid); -- ok
75 DROP MATERIALIZED VIEW tid_matview;
78 CREATE SEQUENCE tid_seq;
79 SELECT currtid2('tid_seq'::text, '(0,1)'::tid); -- ok
85 DROP SEQUENCE tid_seq;
86 -- Index, fails with incorrect relation type
87 CREATE INDEX tid_ind ON tid_tab(a);
88 SELECT currtid2('tid_ind'::text, '(0,1)'::tid); -- fails
89 ERROR: cannot open relation "tid_ind"
90 DETAIL: This operation is not supported for indexes.
92 -- Partitioned table, no storage
93 CREATE TABLE tid_part (a int) PARTITION BY RANGE (a);
94 SELECT currtid2('tid_part'::text, '(0,1)'::tid); -- fails
95 ERROR: cannot look at latest visible tid for relation "public.tid_part"
98 -- ctid not defined in the view
99 CREATE VIEW tid_view_no_ctid AS SELECT a FROM tid_tab;
100 SELECT currtid2('tid_view_no_ctid'::text, '(0,1)'::tid); -- fails
101 ERROR: currtid cannot handle views with no CTID
102 DROP VIEW tid_view_no_ctid;
103 -- ctid fetched directly from the source table.
104 CREATE VIEW tid_view_with_ctid AS SELECT ctid, a FROM tid_tab;
105 SELECT currtid2('tid_view_with_ctid'::text, '(0,1)'::tid); -- fails
106 ERROR: tid (0, 1) is not valid for relation "tid_tab"
107 INSERT INTO tid_tab VALUES (1);
108 SELECT currtid2('tid_view_with_ctid'::text, '(0,1)'::tid); -- ok
114 DROP VIEW tid_view_with_ctid;
116 -- ctid attribute with incorrect data type
117 CREATE VIEW tid_view_fake_ctid AS SELECT 1 AS ctid, 2 AS a;
118 SELECT currtid2('tid_view_fake_ctid'::text, '(0,1)'::tid); -- fails
119 ERROR: ctid isn't of type TID
120 DROP VIEW tid_view_fake_ctid;
121 DROP TABLE tid_tab CASCADE;