Debian Codegraph @

contrib/btree_gist/expected/partitions.out

raw
1 -- Make sure we can create an exclusion constraint
2 -- across a partitioned table.
3 -- That code looks at strategy numbers that can differ in regular gist vs btree_gist,
4 -- so we want to make sure it works here too.
5 create table parttmp (
6 id int,
7 valid_at daterange,
8 exclude using gist (id with =, valid_at with &&)
9 ) partition by range (id);
10 create table parttmp_1_to_10 partition of parttmp for values from (1) to (10);
11 create table parttmp_11_to_20 partition of parttmp for values from (11) to (20);
12 insert into parttmp (id, valid_at) values
13 (1, '[2000-01-01, 2000-02-01)'),
14 (1, '[2000-02-01, 2000-03-01)'),
15 (2, '[2000-01-01, 2000-02-01)'),
16 (11, '[2000-01-01, 2000-02-01)'),
17 (11, '[2000-02-01, 2000-03-01)'),
18 (12, '[2000-01-01, 2000-02-01)');
19 select * from parttmp order by id, valid_at;
20 id | valid_at
21 ----+-------------------------
22 1 | [01-01-2000,02-01-2000)
23 1 | [02-01-2000,03-01-2000)
24 2 | [01-01-2000,02-01-2000)
25 11 | [01-01-2000,02-01-2000)
26 11 | [02-01-2000,03-01-2000)
27 12 | [01-01-2000,02-01-2000)
28 (6 rows)
29
30 select * from parttmp_1_to_10 order by id, valid_at;
31 id | valid_at
32 ----+-------------------------
33 1 | [01-01-2000,02-01-2000)
34 1 | [02-01-2000,03-01-2000)
35 2 | [01-01-2000,02-01-2000)
36 (3 rows)
37
38 select * from parttmp_11_to_20 order by id, valid_at;
39 id | valid_at
40 ----+-------------------------
41 11 | [01-01-2000,02-01-2000)
42 11 | [02-01-2000,03-01-2000)
43 12 | [01-01-2000,02-01-2000)
44 (3 rows)
45
46 update parttmp set valid_at = valid_at * '[2000-01-15,2000-02-15)' where id = 1;
47 select * from parttmp order by id, valid_at;
48 id | valid_at
49 ----+-------------------------
50 1 | [01-15-2000,02-01-2000)
51 1 | [02-01-2000,02-15-2000)
52 2 | [01-01-2000,02-01-2000)
53 11 | [01-01-2000,02-01-2000)
54 11 | [02-01-2000,03-01-2000)
55 12 | [01-01-2000,02-01-2000)
56 (6 rows)
57
58 select * from parttmp_1_to_10 order by id, valid_at;
59 id | valid_at
60 ----+-------------------------
61 1 | [01-15-2000,02-01-2000)
62 1 | [02-01-2000,02-15-2000)
63 2 | [01-01-2000,02-01-2000)
64 (3 rows)
65
66 select * from parttmp_11_to_20 order by id, valid_at;
67 id | valid_at
68 ----+-------------------------
69 11 | [01-01-2000,02-01-2000)
70 11 | [02-01-2000,03-01-2000)
71 12 | [01-01-2000,02-01-2000)
72 (3 rows)
73
74 -- make sure the excluson constraint excludes:
75 insert into parttmp (id, valid_at) values
76 (2, '[2000-01-15, 2000-02-01)');
77 ERROR: conflicting key value violates exclusion constraint "parttmp_1_to_10_id_valid_at_excl"
78 DETAIL: Key (id, valid_at)=(2, [01-15-2000,02-01-2000)) conflicts with existing key (id, valid_at)=(2, [01-01-2000,02-01-2000)).
79 drop table parttmp;
80 -- should fail with a good error message:
81 create table parttmp (id int, valid_at daterange, exclude using gist (id with <>, valid_at with &&)) partition by range (id);
82 ERROR: cannot match partition key to index on column "id" using non-equal operator "<>"