Re: clausula ilike

From: "deepthroat" <dblackbeer(at)gmail(dot)com>
To: deepthroat <dblackbeer(at)gmail(dot)com>, pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: clausula ilike
Date: 2005-10-18 19:00:10
Message-ID: 1f3528fc0510181200l19df1a98p@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

El 18/10/05, Alvaro Herrera<alvherre(at)alvh(dot)no-ip(dot)org> escribió:
> deepthroat escribió:
> > Cuando utilizo la clausula ilike jamas usa índices?
>
> Efectivamente. Para poder hacer busquedas sin sensibilidad a mayusculas
> y que al mismo tiempo puedan usar un indice, crea un indice funcional en
> to_upper(columna) y luego haces las consultas de la misma forma:
>
> where to_upper(columna) = to_upper('alguna palabra')
>
> Observa que no puedes usar comodines en este caso ... no estoy seguro si
> se usara el indice cuando haces
>
> where to_upper(columna) like to_upper('alguna palabra%')

acabo de probar y lo hace:

tracer=# create index idxage_002 on agentes (upper(apellido));

tracer=# explain analyze select * from agentes where upper(apellido)
like upper('kob%');

QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
Index Scan using idxage_002 on agentes (cost=0.01..1104.54 rows=284
width=459) (actual time=0.063..0.139 rows=4 loops=1)
Index Cond: ((upper((apellido)::text) >= 'KOB'::text) AND
(upper((apellido)::text) < 'KOC'::text))
Filter: (upper((apellido)::text) ~~ 'KOB%'::text)
Total runtime: 0.257 ms

Muchas gracias

>
> --
> Alvaro Herrera http://www.amazon.com/gp/registry/CTMLCN8V17R4
> "Now I have my system running, not a byte was off the shelf;
> It rarely breaks and when it does I fix the code myself.
> It's stable, clean and elegant, and lightning fast as well,
> And it doesn't cost a nickel, so Bill Gates can go to hell."
>

--
Está utilizando 40 MB (2%) de sus 2653 MB.

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Diego Gil 2005-10-18 19:02:55 Traducción
Previous Message Ma. Elizabeth Illatarco 2005-10-18 18:51:02 Despedida