1-- date check
2CREATE TABLE datetmp (a date);
3\copy datetmp from 'data/date.data'
4SET enable_seqscan=on;
5SELECT count(*) FROM datetmp WHERE a <  '2001-02-13';
6 count
7-------
8   230
9(1 row)
10
11SELECT count(*) FROM datetmp WHERE a <= '2001-02-13';
12 count
13-------
14   231
15(1 row)
16
17SELECT count(*) FROM datetmp WHERE a  = '2001-02-13';
18 count
19-------
20     1
21(1 row)
22
23SELECT count(*) FROM datetmp WHERE a >= '2001-02-13';
24 count
25-------
26   314
27(1 row)
28
29SELECT count(*) FROM datetmp WHERE a >  '2001-02-13';
30 count
31-------
32   313
33(1 row)
34
35SELECT a, a <-> '2001-02-13' FROM datetmp ORDER BY a <-> '2001-02-13' LIMIT 3;
36     a      | ?column?
37------------+----------
38 02-13-2001 |        0
39 02-11-2001 |        2
40 03-24-2001 |       39
41(3 rows)
42
43CREATE INDEX dateidx ON datetmp USING gist ( a );
44SET enable_seqscan=off;
45SELECT count(*) FROM datetmp WHERE a <  '2001-02-13'::date;
46 count
47-------
48   230
49(1 row)
50
51SELECT count(*) FROM datetmp WHERE a <= '2001-02-13'::date;
52 count
53-------
54   231
55(1 row)
56
57SELECT count(*) FROM datetmp WHERE a  = '2001-02-13'::date;
58 count
59-------
60     1
61(1 row)
62
63SELECT count(*) FROM datetmp WHERE a >= '2001-02-13'::date;
64 count
65-------
66   314
67(1 row)
68
69SELECT count(*) FROM datetmp WHERE a >  '2001-02-13'::date;
70 count
71-------
72   313
73(1 row)
74
75EXPLAIN (COSTS OFF)
76SELECT a, a <-> '2001-02-13' FROM datetmp ORDER BY a <-> '2001-02-13' LIMIT 3;
77                   QUERY PLAN
78------------------------------------------------
79 Limit
80   ->  Index Only Scan using dateidx on datetmp
81         Order By: (a <-> '02-13-2001'::date)
82(3 rows)
83
84SELECT a, a <-> '2001-02-13' FROM datetmp ORDER BY a <-> '2001-02-13' LIMIT 3;
85     a      | ?column?
86------------+----------
87 02-13-2001 |        0
88 02-11-2001 |        2
89 03-24-2001 |       39
90(3 rows)
91
92