From: | "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: question about performance |
Date: | 2008-07-20 18:36:48 |
Message-ID: | 20080720183647.GA23477@a-kretschmer.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
am Sun, dem 20.07.2008, um 20:08:21 +0200 mailte Robert Urban folgendes:
> Hi PostgreSQLer,
>
> if I have a table, the_table, with a DATE field, i'll call it 'day', and
> I'd like to find all rows whos day falls within a given month, which of the
> following methods is faster/costs less:
>
> 1.
>
> SELECT * FROM the_table WHERE day LIKE '2008-01-%';
>
> 2.
>
> SELECT * FROM the_table
> WHERE ( day BETWEEN '$month_begin' AND '$month_end' );
>
> # where $month_begin is '2008-01-01' and $month_end is '2008-01-31';
Probably the second one, but it depends if you have a propper index.
Other solution: create a functional index based on date_trunc and
rewrite your where-condition also.
Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net
From | Date | Subject | |
---|---|---|---|
Next Message | Alan Hodgson | 2008-07-20 18:40:59 | Re: question about performance |
Previous Message | Robert Urban | 2008-07-20 18:08:21 | question about performance |