pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
two dates
4+ messages / 4 participants
[nested] [flat]

* two dates
@ 2003-02-25 06:55  mixo <mixo@beth.uniforum.org.za>
  0 siblings, 2 replies; 4+ messages in thread

From: mixo @ 2003-02-25 06:55 UTC (permalink / raw)
  To: pgsql-sql

I have a table which has serveral time stamps include when an entry was 
'created'.
Each entry is identified by a unique 'id'. How can I best find entries 
created
between two dates without going through each day between the two dates?

Currently, going through each day to get the results takes about 23 
minutes for 7 days
as I have two other criteria for search: roughly I am doing about 
16*17*n queries,
where n=days between two dates (for 7 days, 16*17*7 = which a number 
that is
too big for my liking).





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: two dates
@ 2003-03-03 12:09  Richard Huxton <dev@archonet.com>
  parent: mixo <mixo@beth.uniforum.org.za>
  1 sibling, 1 reply; 4+ messages in thread

From: Richard Huxton @ 2003-03-03 12:09 UTC (permalink / raw)
  To: mixo <mixo@beth.uniforum.org.za>; pgsql-sql

On Tuesday 25 Feb 2003 6:55 am, mixo wrote:
> I have a table which has serveral time stamps include when an entry was
> 'created'.
> Each entry is identified by a unique 'id'. How can I best find entries
> created
> between two dates without going through each day between the two dates?
>
> Currently, going through each day to get the results takes about 23
> minutes for 7 days
> as I have two other criteria for search: roughly I am doing about
> 16*17*n queries,
> where n=days between two dates (for 7 days, 16*17*7 = which a number
> that is
> too big for my liking).

What is wrong with SELECT id FROM foo WHERE created_date>='2003-01-01' AND 
created_date<='2003-01-07' or similar? I don't see why you need multiple 
queries, perhaps I have misunderstood

-- 
  Richard Huxton



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: two dates
@ 2003-03-03 12:32  Oliver Elphick <olly@lfix.co.uk>
  parent: Richard Huxton <dev@archonet.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Oliver Elphick @ 2003-03-03 12:32 UTC (permalink / raw)
  To: Richard Huxton <dev@archonet.com>; +Cc: mixo <mixo@beth.uniforum.org.za>; pgsql-sql

On Mon, 2003-03-03 at 12:09, Richard Huxton wrote:
> What is wrong with SELECT id FROM foo WHERE created_date>='2003-01-01' AND 
> created_date<='2003-01-07' or similar? I don't see why you need multiple 
> queries, perhaps I have misunderstood

The BETWEEN operator is provided for this precise requirement:

 SELECT id FROM foo WHERE created_date BETWEEN '2003-01-01' AND '2003-01-07';

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                             http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "A new commandment I give to you, that you love one
      another, even as I have loved you."
                                        John 13:34




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: two dates
@ 2003-03-16 22:37  D.Sanchez <dsanchezREMOVE@bigpond.com>
  parent: mixo <mixo@beth.uniforum.org.za>
  1 sibling, 0 replies; 4+ messages in thread

From: D.Sanchez @ 2003-03-16 22:37 UTC (permalink / raw)
  To: pgsql-sql

If you just want to select all entries created between two given dates, the
following query should do it:

SELECT column1, column2, ....
FROM table
WHERE creation_date between to_date('date1','date_format') and
to_date('date2','date_format')
order by creation_date;

This will find all the entries with a creation_date between date1 and date2
and it return the rows sorted by the creation date. You can add additional
selection critirias to the WHERE clause if needed.

David

"mixo" <mixo@beth.uniforum.org.za> wrote in message
news:3E5B1349.80705@beth.uniforum.org.za...
> I have a table which has serveral time stamps include when an entry was
> 'created'.
> Each entry is identified by a unique 'id'. How can I best find entries
> created
> between two dates without going through each day between the two dates?
>
> Currently, going through each day to get the results takes about 23
> minutes for 7 days
> as I have two other criteria for search: roughly I am doing about
> 16*17*n queries,
> where n=days between two dates (for 7 days, 16*17*7 = which a number
> that is
> too big for my liking).
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2003-03-16 22:37 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-02-25 06:55 two dates mixo <mixo@beth.uniforum.org.za>
2003-03-03 12:09 ` Richard Huxton <dev@archonet.com>
2003-03-03 12:32   ` Oliver Elphick <olly@lfix.co.uk>
2003-03-16 22:37 ` D.Sanchez <dsanchezREMOVE@bigpond.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox