1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
CREATE TABLE test_timestamp (
i timestamp
);
INSERT INTO test_timestamp VALUES
( '2004-10-26 03:55:08' ),
( '2004-10-26 04:55:08' ),
( '2004-10-26 05:55:08' ),
( '2004-10-26 08:55:08' ),
( '2004-10-26 09:55:08' ),
( '2004-10-26 10:55:08' )
;
SELECT i <=> '2004-10-26 06:24:08', i FROM test_timestamp ORDER BY 1, 2 ASC;
?column? | i
----------+--------------------------
1740 | Tue Oct 26 05:55:08 2004
5340 | Tue Oct 26 04:55:08 2004
8940 | Tue Oct 26 03:55:08 2004
9060 | Tue Oct 26 08:55:08 2004
12660 | Tue Oct 26 09:55:08 2004
16260 | Tue Oct 26 10:55:08 2004
(6 rows)
SELECT i <=| '2004-10-26 06:24:08', i FROM test_timestamp ORDER BY 1, 2 ASC;
?column? | i
----------+--------------------------
1740 | Tue Oct 26 05:55:08 2004
5340 | Tue Oct 26 04:55:08 2004
8940 | Tue Oct 26 03:55:08 2004
Infinity | Tue Oct 26 08:55:08 2004
Infinity | Tue Oct 26 09:55:08 2004
Infinity | Tue Oct 26 10:55:08 2004
(6 rows)
SELECT i |=> '2004-10-26 06:24:08', i FROM test_timestamp ORDER BY 1, 2 ASC;
?column? | i
----------+--------------------------
9060 | Tue Oct 26 08:55:08 2004
12660 | Tue Oct 26 09:55:08 2004
16260 | Tue Oct 26 10:55:08 2004
Infinity | Tue Oct 26 03:55:08 2004
Infinity | Tue Oct 26 04:55:08 2004
Infinity | Tue Oct 26 05:55:08 2004
(6 rows)
CREATE INDEX idx_timestamp ON test_timestamp USING rum (i);
set enable_seqscan=off;
explain (costs off)
SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamp ORDER BY i;
QUERY PLAN
-----------------------------------------------------------------------------------
Sort
Sort Key: i
-> Index Scan using idx_timestamp on test_timestamp
Index Cond: (i < 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
(4 rows)
SELECT * FROM test_timestamp WHERE i<'2004-10-26 08:55:08'::timestamp ORDER BY i;
i
--------------------------
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
(3 rows)
explain (costs off)
SELECT * FROM test_timestamp WHERE i<='2004-10-26 08:55:08'::timestamp ORDER BY i;
QUERY PLAN
------------------------------------------------------------------------------------
Sort
Sort Key: i
-> Index Scan using idx_timestamp on test_timestamp
Index Cond: (i <= 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
(4 rows)
SELECT * FROM test_timestamp WHERE i<='2004-10-26 08:55:08'::timestamp ORDER BY i;
i
--------------------------
Tue Oct 26 03:55:08 2004
Tue Oct 26 04:55:08 2004
Tue Oct 26 05:55:08 2004
Tue Oct 26 08:55:08 2004
(4 rows)
explain (costs off)
SELECT * FROM test_timestamp WHERE i='2004-10-26 08:55:08'::timestamp ORDER BY i;
QUERY PLAN
-----------------------------------------------------------------------------
Index Scan using idx_timestamp on test_timestamp
Index Cond: (i = 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
(2 rows)
SELECT * FROM test_timestamp WHERE i='2004-10-26 08:55:08'::timestamp ORDER BY i;
i
--------------------------
Tue Oct 26 08:55:08 2004
(1 row)
explain (costs off)
SELECT * FROM test_timestamp WHERE i>='2004-10-26 08:55:08'::timestamp ORDER BY i;
QUERY PLAN
------------------------------------------------------------------------------------
Sort
Sort Key: i
-> Index Scan using idx_timestamp on test_timestamp
Index Cond: (i >= 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
(4 rows)
SELECT * FROM test_timestamp WHERE i>='2004-10-26 08:55:08'::timestamp ORDER BY i;
i
--------------------------
Tue Oct 26 08:55:08 2004
Tue Oct 26 09:55:08 2004
Tue Oct 26 10:55:08 2004
(3 rows)
explain (costs off)
SELECT * FROM test_timestamp WHERE i>'2004-10-26 08:55:08'::timestamp ORDER BY i;
QUERY PLAN
-----------------------------------------------------------------------------------
Sort
Sort Key: i
-> Index Scan using idx_timestamp on test_timestamp
Index Cond: (i > 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
(4 rows)
SELECT * FROM test_timestamp WHERE i>'2004-10-26 08:55:08'::timestamp ORDER BY i;
i
--------------------------
Tue Oct 26 09:55:08 2004
Tue Oct 26 10:55:08 2004
(2 rows)
explain (costs off)
SELECT *, i <=> '2004-10-26 08:55:08'::timestamp FROM test_timestamp
ORDER BY i <=> '2004-10-26 08:55:08'::timestamp;
QUERY PLAN
-----------------------------------------------------------------------------
Index Scan using idx_timestamp on test_timestamp
Order By: (i <=> 'Tue Oct 26 08:55:08 2004'::timestamp without time zone)
(2 rows)
SELECT *, i <=> '2004-10-26 08:55:08'::timestamp FROM test_timestamp
ORDER BY i <=> '2004-10-26 08:55:08'::timestamp;
i | ?column?
--------------------------+----------
Tue Oct 26 08:55:08 2004 | 0
Tue Oct 26 09:55:08 2004 | 3600
Tue Oct 26 10:55:08 2004 | 7200
Tue Oct 26 05:55:08 2004 | 10800
Tue Oct 26 04:55:08 2004 | 14400
Tue Oct 26 03:55:08 2004 | 18000
(6 rows)
explain (costs off)
SELECT *, i <=> '2004-10-26 05:00:00'::timestamp FROM test_timestamp
WHERE i>'2004-10-26 05:00:00'::timestamp ORDER BY i <=> '2004-10-26 05:00:00'::timestamp;
QUERY PLAN
-----------------------------------------------------------------------------
Index Scan using idx_timestamp on test_timestamp
Index Cond: (i > 'Tue Oct 26 05:00:00 2004'::timestamp without time zone)
Order By: (i <=> 'Tue Oct 26 05:00:00 2004'::timestamp without time zone)
(3 rows)
SELECT *, i <=> '2004-10-26 05:00:00'::timestamp FROM test_timestamp
WHERE i>'2004-10-26 05:00:00'::timestamp ORDER BY i <=> '2004-10-26 05:00:00'::timestamp;
i | ?column?
--------------------------+----------
Tue Oct 26 05:55:08 2004 | 3308
Tue Oct 26 08:55:08 2004 | 14108
Tue Oct 26 09:55:08 2004 | 17708
Tue Oct 26 10:55:08 2004 | 21308
(4 rows)
-- Tests for timestamptz
SELECT i::timestamptz AS i INTO test_timestamptz FROM test_timestamp;
CREATE INDEX idx_timestamptz ON test_timestamptz USING rum (i);
explain (costs off)
SELECT * FROM test_timestamptz WHERE i>'2004-10-26 08:55:08'::timestamptz ORDER BY i;
QUERY PLAN
------------------------------------------------------------------------------------
Sort
Sort Key: i
-> Index Scan using idx_timestamptz on test_timestamptz
Index Cond: (i > 'Tue Oct 26 08:55:08 2004 PDT'::timestamp with time zone)
(4 rows)
SELECT * FROM test_timestamptz WHERE i>'2004-10-26 08:55:08'::timestamptz ORDER BY i;
i
------------------------------
Tue Oct 26 09:55:08 2004 PDT
Tue Oct 26 10:55:08 2004 PDT
(2 rows)
explain (costs off)
SELECT *, i <=> '2004-10-26 08:55:08'::timestamptz FROM test_timestamptz
ORDER BY i <=> '2004-10-26 08:55:08'::timestamptz;
QUERY PLAN
------------------------------------------------------------------------------
Index Scan using idx_timestamptz on test_timestamptz
Order By: (i <=> 'Tue Oct 26 08:55:08 2004 PDT'::timestamp with time zone)
(2 rows)
SELECT *, i <=> '2004-10-26 08:55:08'::timestamptz FROM test_timestamptz
ORDER BY i <=> '2004-10-26 08:55:08'::timestamptz;
i | ?column?
------------------------------+----------
Tue Oct 26 08:55:08 2004 PDT | 0
Tue Oct 26 09:55:08 2004 PDT | 3600
Tue Oct 26 10:55:08 2004 PDT | 7200
Tue Oct 26 05:55:08 2004 PDT | 10800
Tue Oct 26 04:55:08 2004 PDT | 14400
Tue Oct 26 03:55:08 2004 PDT | 18000
(6 rows)
explain (costs off)
SELECT *, i <=> '2004-10-26 05:00:00'::timestamptz FROM test_timestamptz
WHERE i>'2004-10-26 05:00:00'::timestamptz ORDER BY i <=> '2004-10-26 05:00:00'::timestamptz;
QUERY PLAN
------------------------------------------------------------------------------
Index Scan using idx_timestamptz on test_timestamptz
Index Cond: (i > 'Tue Oct 26 05:00:00 2004 PDT'::timestamp with time zone)
Order By: (i <=> 'Tue Oct 26 05:00:00 2004 PDT'::timestamp with time zone)
(3 rows)
SELECT *, i <=> '2004-10-26 05:00:00'::timestamptz FROM test_timestamptz
WHERE i>'2004-10-26 05:00:00'::timestamptz ORDER BY i <=> '2004-10-26 05:00:00'::timestamptz;
i | ?column?
------------------------------+----------
Tue Oct 26 05:55:08 2004 PDT | 3308
Tue Oct 26 08:55:08 2004 PDT | 14108
Tue Oct 26 09:55:08 2004 PDT | 17708
Tue Oct 26 10:55:08 2004 PDT | 21308
(4 rows)
|