1-- enum check
2create type rainbow as enum ('r','o','y','g','b','i','v');
3CREATE TABLE enumtmp (a rainbow);
4\copy enumtmp from 'data/enum.data'
5SET enable_seqscan=on;
6select a, count(*) from enumtmp group by a order by 1;
7 a | count
8---+-------
9 r |    76
10 o |    78
11 y |    73
12 g |    75
13 b |    77
14 i |    78
15 v |    75
16   |    63
17(8 rows)
18
19SELECT count(*) FROM enumtmp WHERE a <  'g'::rainbow;
20 count
21-------
22   227
23(1 row)
24
25SELECT count(*) FROM enumtmp WHERE a <= 'g'::rainbow;
26 count
27-------
28   302
29(1 row)
30
31SELECT count(*) FROM enumtmp WHERE a  = 'g'::rainbow;
32 count
33-------
34    75
35(1 row)
36
37SELECT count(*) FROM enumtmp WHERE a >= 'g'::rainbow;
38 count
39-------
40   305
41(1 row)
42
43SELECT count(*) FROM enumtmp WHERE a >  'g'::rainbow;
44 count
45-------
46   230
47(1 row)
48
49CREATE INDEX enumidx ON enumtmp USING gist ( a );
50SET enable_seqscan=off;
51SELECT count(*) FROM enumtmp WHERE a <  'g'::rainbow;
52 count
53-------
54   227
55(1 row)
56
57SELECT count(*) FROM enumtmp WHERE a <= 'g'::rainbow;
58 count
59-------
60   302
61(1 row)
62
63SELECT count(*) FROM enumtmp WHERE a  = 'g'::rainbow;
64 count
65-------
66    75
67(1 row)
68
69SELECT count(*) FROM enumtmp WHERE a >= 'g'::rainbow;
70 count
71-------
72   305
73(1 row)
74
75SELECT count(*) FROM enumtmp WHERE a >  'g'::rainbow;
76 count
77-------
78   230
79(1 row)
80
81EXPLAIN (COSTS OFF)
82SELECT count(*) FROM enumtmp WHERE a >= 'g'::rainbow;
83                  QUERY PLAN
84-----------------------------------------------
85 Aggregate
86   ->  Bitmap Heap Scan on enumtmp
87         Recheck Cond: (a >= 'g'::rainbow)
88         ->  Bitmap Index Scan on enumidx
89               Index Cond: (a >= 'g'::rainbow)
90(5 rows)
91
92