Skip to content

Commit a5c8cb7

Browse files
committed
improve interval tests
1 parent 80476ef commit a5c8cb7

File tree

2 files changed

+144
-6
lines changed

2 files changed

+144
-6
lines changed

expected/pathman_interval.out

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,102 @@
11
\set VERBOSITY terse
22
CREATE EXTENSION pg_pathman;
33
CREATE SCHEMA test_interval;
4-
/* Range partitions for INTEGER type */
5-
CREATE TABLE test_interval.abc (id SERIAL);
4+
/* Range partitions for INT2 type */
5+
CREATE TABLE test_interval.abc (id INT2 NOT NULL);
66
SELECT create_range_partitions('test_interval.abc', 'id', 0, 100, 2);
77
NOTICE: sequence "abc_seq" does not exist, skipping
88
create_range_partitions
99
-------------------------
1010
2
1111
(1 row)
1212

13-
SELECT set_interval('test_interval.abc', NULL::INTEGER);
13+
SELECT set_interval('test_interval.abc', NULL::INT2);
14+
set_interval
15+
--------------
16+
17+
(1 row)
18+
19+
/* pg_pathman shouldn't be able to create a new partition */
20+
INSERT INTO test_interval.abc VALUES (250);
21+
ERROR: cannot find appropriate partition for key '250'
22+
/* Set a trivial interval */
23+
SELECT set_interval('test_interval.abc', 0);
24+
ERROR: interval must not be trivial
25+
/* Set a negative interval */
26+
SELECT set_interval('test_interval.abc', -100);
27+
ERROR: interval must not be negative
28+
/* We also shouldn't be able to set a trivial interval directly */
29+
UPDATE pathman_config SET range_interval = '0'
30+
WHERE partrel = 'test_interval.abc'::REGCLASS;
31+
ERROR: interval must not be trivial
32+
/* Set a normal interval */
33+
SELECT set_interval('test_interval.abc', 1000);
34+
set_interval
35+
--------------
36+
37+
(1 row)
38+
39+
INSERT INTO test_interval.abc VALUES (250);
40+
SELECT * FROM pathman_config;
41+
partrel | attname | parttype | range_interval
42+
-------------------+---------+----------+----------------
43+
test_interval.abc | id | 2 | 1000
44+
(1 row)
45+
46+
DROP TABLE test_interval.abc CASCADE;
47+
NOTICE: drop cascades to 3 other objects
48+
/* Range partitions for INT4 type */
49+
CREATE TABLE test_interval.abc (id INT4 NOT NULL);
50+
SELECT create_range_partitions('test_interval.abc', 'id', 0, 100, 2);
51+
create_range_partitions
52+
-------------------------
53+
2
54+
(1 row)
55+
56+
SELECT set_interval('test_interval.abc', NULL::INT4);
57+
set_interval
58+
--------------
59+
60+
(1 row)
61+
62+
/* pg_pathman shouldn't be able to create a new partition */
63+
INSERT INTO test_interval.abc VALUES (250);
64+
ERROR: cannot find appropriate partition for key '250'
65+
/* Set a trivial interval */
66+
SELECT set_interval('test_interval.abc', 0);
67+
ERROR: interval must not be trivial
68+
/* Set a negative interval */
69+
SELECT set_interval('test_interval.abc', -100);
70+
ERROR: interval must not be negative
71+
/* We also shouldn't be able to set a trivial interval directly */
72+
UPDATE pathman_config SET range_interval = '0'
73+
WHERE partrel = 'test_interval.abc'::REGCLASS;
74+
ERROR: interval must not be trivial
75+
/* Set a normal interval */
76+
SELECT set_interval('test_interval.abc', 1000);
77+
set_interval
78+
--------------
79+
80+
(1 row)
81+
82+
INSERT INTO test_interval.abc VALUES (250);
83+
SELECT * FROM pathman_config;
84+
partrel | attname | parttype | range_interval
85+
-------------------+---------+----------+----------------
86+
test_interval.abc | id | 2 | 1000
87+
(1 row)
88+
89+
DROP TABLE test_interval.abc CASCADE;
90+
NOTICE: drop cascades to 3 other objects
91+
/* Range partitions for INT8 type */
92+
CREATE TABLE test_interval.abc (id INT8 NOT NULL);
93+
SELECT create_range_partitions('test_interval.abc', 'id', 0, 100, 2);
94+
create_range_partitions
95+
-------------------------
96+
2
97+
(1 row)
98+
99+
SELECT set_interval('test_interval.abc', NULL::INT8);
14100
set_interval
15101
--------------
16102

sql/pathman_interval.sql

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,62 @@ CREATE SCHEMA test_interval;
55

66

77

8-
/* Range partitions for INTEGER type */
9-
CREATE TABLE test_interval.abc (id SERIAL);
8+
/* Range partitions for INT2 type */
9+
CREATE TABLE test_interval.abc (id INT2 NOT NULL);
1010
SELECT create_range_partitions('test_interval.abc', 'id', 0, 100, 2);
11-
SELECT set_interval('test_interval.abc', NULL::INTEGER);
11+
SELECT set_interval('test_interval.abc', NULL::INT2);
12+
13+
/* pg_pathman shouldn't be able to create a new partition */
14+
INSERT INTO test_interval.abc VALUES (250);
15+
16+
/* Set a trivial interval */
17+
SELECT set_interval('test_interval.abc', 0);
18+
19+
/* Set a negative interval */
20+
SELECT set_interval('test_interval.abc', -100);
21+
22+
/* We also shouldn't be able to set a trivial interval directly */
23+
UPDATE pathman_config SET range_interval = '0'
24+
WHERE partrel = 'test_interval.abc'::REGCLASS;
25+
26+
/* Set a normal interval */
27+
SELECT set_interval('test_interval.abc', 1000);
28+
INSERT INTO test_interval.abc VALUES (250);
29+
SELECT * FROM pathman_config;
30+
31+
DROP TABLE test_interval.abc CASCADE;
32+
33+
34+
/* Range partitions for INT4 type */
35+
CREATE TABLE test_interval.abc (id INT4 NOT NULL);
36+
SELECT create_range_partitions('test_interval.abc', 'id', 0, 100, 2);
37+
SELECT set_interval('test_interval.abc', NULL::INT4);
38+
39+
/* pg_pathman shouldn't be able to create a new partition */
40+
INSERT INTO test_interval.abc VALUES (250);
41+
42+
/* Set a trivial interval */
43+
SELECT set_interval('test_interval.abc', 0);
44+
45+
/* Set a negative interval */
46+
SELECT set_interval('test_interval.abc', -100);
47+
48+
/* We also shouldn't be able to set a trivial interval directly */
49+
UPDATE pathman_config SET range_interval = '0'
50+
WHERE partrel = 'test_interval.abc'::REGCLASS;
51+
52+
/* Set a normal interval */
53+
SELECT set_interval('test_interval.abc', 1000);
54+
INSERT INTO test_interval.abc VALUES (250);
55+
SELECT * FROM pathman_config;
56+
57+
DROP TABLE test_interval.abc CASCADE;
58+
59+
60+
/* Range partitions for INT8 type */
61+
CREATE TABLE test_interval.abc (id INT8 NOT NULL);
62+
SELECT create_range_partitions('test_interval.abc', 'id', 0, 100, 2);
63+
SELECT set_interval('test_interval.abc', NULL::INT8);
1264

1365
/* pg_pathman shouldn't be able to create a new partition */
1466
INSERT INTO test_interval.abc VALUES (250);

0 commit comments

Comments
 (0)