Re: [Pgsql-ayuda] Indices ...

From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Martin Marques <martin(at)bugs(dot)unl(dot)edu(dot)ar>
Cc: Carmen Gloria Sepulveda Dedes <csepulveda(at)atichile(dot)com>, pgsql-ayuda(at)tlali(dot)iztacala(dot)unam(dot)mx
Subject: Re: [Pgsql-ayuda] Indices ...
Date: 2003-09-10 23:09:09
Message-ID: 20030910230909.GE5175@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

On Wed, Sep 10, 2003 at 05:13:50PM -0300, Martin Marques wrote:
> El Mié 10 Sep 2003 16:34, Carmen Gloria Sepulveda Dedes escribió:

> > Si yo tengo una tabla con un campo
> > de tipo timestamp y lo consulto usando
> > las funciones date_part o date_trunc y tambien
> > uso estas funciones en el where ...
>
> Tenes que crear un indice de funcion:
>
> CREATE INDEX nombre_idx ON nombre_tabla (date_part(nombre_col))

Ojo... los indices funcionales hasta 7.3 (inclusive) no pueden llevar
constantes en la definicion. O sea esto no es valido:

CREATE INDEX nombre_idx ON nombre_tabla (date_part(nombre_col, 'month'))

Para poder hacer esto, tienes que crear una funcion del estilo

CREATE FUNCTION date_part_month (timestamp) returns double AS '
select date_part($1, ''month'')' LANGUAGE SQL;

y crear un indice usando esa funcion (declarada inmutable y todo eso,
por supuesto).

Esto fue corregido por Tom Lane para 7.4, disponible en forma de beta en
su mirror más cercano.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"I can't go to a restaurant and order food because I keep looking at the
fonts on the menu. Five minutes later I realize that it's also talking
about food" (Donald Knuth)

In response to

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2003-09-10 23:30:04 Re: [Pgsql-ayuda] error
Previous Message Felipe Fernandez 2003-09-10 22:21:00 [Pgsql-ayuda] error