Debian Codegraph @

contrib/btree_gist/sql/partitions.sql

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
11 create table parttmp_1_to_10 partition of parttmp for values from (1) to (10);
12 create table parttmp_11_to_20 partition of parttmp for values from (11) to (20);
13
14 insert into parttmp (id, valid_at) values
15 (1, '[2000-01-01, 2000-02-01)'),
16 (1, '[2000-02-01, 2000-03-01)'),
17 (2, '[2000-01-01, 2000-02-01)'),
18 (11, '[2000-01-01, 2000-02-01)'),
19 (11, '[2000-02-01, 2000-03-01)'),
20 (12, '[2000-01-01, 2000-02-01)');
21
22 select * from parttmp order by id, valid_at;
23 select * from parttmp_1_to_10 order by id, valid_at;
24 select * from parttmp_11_to_20 order by id, valid_at;
25
26 update parttmp set valid_at = valid_at * '[2000-01-15,2000-02-15)' where id = 1;
27
28 select * from parttmp order by id, valid_at;
29 select * from parttmp_1_to_10 order by id, valid_at;
30 select * from parttmp_11_to_20 order by id, valid_at;
31
32 -- make sure the excluson constraint excludes:
33 insert into parttmp (id, valid_at) values
34 (2, '[2000-01-15, 2000-02-01)');
35
36 drop table parttmp;
37
38 -- should fail with a good error message:
39 create table parttmp (id int, valid_at daterange, exclude using gist (id with <>, valid_at with &&)) partition by range (id);