title: select records from postgres where timestamp is in certain range
body: <p>I have arrival column of type timestamp in table reservations ( I'm using postgres ).
  How would I select all dates within this year for example?</p>
  
  <p>I know I could do something like this:</p>
  
  <pre><code>select * FROM reservations WHERE extract(year from arrival) = 2012;
  </code></pre>
  
  <p>But I've ran <strong>analyze</strong> and it looks like it require a sequence scan. 
  Is there a better option?</p>
  
  <p><strong>P.S. 1 Hmm. both ways seem to require seq. scan. But the one by wildplasser produces results faster - why?</strong></p>
  
  <pre><code>cmm=# EXPLAIN ANALYZE select * FROM reservations WHERE extract(year from arrival) = 2010;
                                                    QUERY PLAN                                                   
  ---------------------------------------------------------------------------------------------------------------
   Seq Scan on vrreservations  (cost=0.00..165.78 rows=14 width=4960) (actual time=0.213..4.509 rows=49 loops=1)
     Filter: (date_part('year'::text, arrival) = 2010::double precision)
   Total runtime: 5.615 ms
  (3 rows)
  
  cmm=# EXPLAIN ANALYZE SELECT * from reservations WHERE arrival &gt; '2010-01-01 00:00:00' AND arrival &lt; '2011-01-01 00:00:00';
                                                                    QUERY PLAN                                                                   
  -----------------------------------------------------------------------------------------------------------------------------------------------
   Seq Scan on reservations  (cost=0.00..165.78 rows=51 width=4960) (actual time=0.126..2.491 rows=49 loops=1)
     Filter: ((arrival &gt; '2010-01-01 00:00:00'::timestamp without time zone) AND (arrival &lt; '2011-01-01 00:00:00'::timestamp without time zone))
   Total runtime: 3.144 ms
  (3 rows)
  </code></pre>
  
  <p>** P.S. 2  - After I have created index on arrival column second way got even faster - since it looks like query uses index. Mkey - I guess I'll stik with this one. **</p>
  
  <pre><code>                                                                       QUERY PLAN                                                                        
  ---------------------------------------------------------------------------------------------------------------------------------------------------------
   Bitmap Heap Scan on reservations  (cost=4.77..101.27 rows=51 width=4960) (actual time=0.359..0.791 rows=49 loops=1)
     Recheck Cond: ((arrival &gt; '2010-01-01 00:00:00'::timestamp without time zone) AND (arrival &lt; '2011-01-01 00:00:00'::timestamp without time zone))
     -&gt;  Bitmap Index Scan on arrival_idx  (cost=0.00..4.76 rows=51 width=0) (actual time=0.177..0.177 rows=49 loops=1)
           Index Cond: ((arrival &gt; '2010-01-01 00:00:00'::timestamp without time zone) AND (arrival &lt; '2011-01-01 00:00:00'::timestamp without time zone))
   Total runtime: 1.265 ms
  </code></pre>