Re: SQL timestamp to date cast

From: "Andrei Bintintan" <klodoma(at)ar-sd(dot)net>
To: "Michael Fuhr" <mike(at)fuhr(dot)org>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: SQL timestamp to date cast
Date: 2005-01-20 09:41:41
Message-ID: 010a01c4fed4$3fba1ca0$0b00a8c0@forge
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> Another possibility would be to create a functional index on datetime:
>
> CREATE INDEX user_action_date_idx ON user_action (date(datetime));

GREAT!!! I thought it is possible but I didn't knew how to make such
indexes. :))

Thank you !!!
Andy.

----- Original Message -----
From: "Michael Fuhr" <mike(at)fuhr(dot)org>
To: "Andrei Bintintan" <klodoma(at)ar-sd(dot)net>
Cc: <pgsql-sql(at)postgresql(dot)org>
Sent: Thursday, January 20, 2005 11:33 AM
Subject: Re: [SQL] SQL timestamp to date cast

> On Thu, Jan 20, 2005 at 10:52:50AM +0200, Andrei Bintintan wrote:
>
>> SELECT DISTINCT(nummer)
>> FROM user_action
>> WHERE datetime::date='11/11/2004' AND id_action IN (5,6,9)
>>
>> Now, datetime has the type timestamp. How can I make an index or write
>> different this query so that it runs faster?
>
> You could create an index on datetime and rewrite your queries:
>
> CREATE INDEX user_action_datetime_idx ON user_action (datetime);
>
> SELECT DISTINCT(nummer)
> FROM user_action
> WHERE datetime >= '11/11/2004' AND datetime < '11/12/2004'
> AND id_action IN (5,6,9);
>
> Another possibility would be to create a functional index on datetime:
>
> CREATE INDEX user_action_date_idx ON user_action (date(datetime));
>
> SELECT DISTINCT(nummer)
> FROM user_action
> WHERE date(datetime) = '11/11/2004' AND id_action IN (5,6,9);
>
> --
> Michael Fuhr
> http://www.fuhr.org/~mfuhr/
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2005-01-20 09:51:16 Re: SQL timestamp to date cast
Previous Message Silke Trissl 2005-01-20 09:39:47 Problem on Geometric functions