Re: question about performance

From: Torsten Zühlsdorff <foo(at)meisterderspiele(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: question about performance
Date: 2008-07-21 07:40:19
Message-ID: g61eh4$ivj$1@registered.motzarella.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

A. Kretschmer schrieb:

>> 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.

Can you give an example?

Greetings,
Torsten

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message el dorado 2008-07-21 08:33:47 Re: C-procedure crashed in Postgres 8.3.3 when using 'text' variable (WinXP) - additional
Previous Message Martin 2008-07-20 22:50:30 Field size