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