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::timestamptz AS i INTO test_timestamptz FROM test_timestamp; 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); CREATE INDEX idx_timestamptz ON test_timestamptz 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 * 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)