Re: find a string contained in an attribute

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Szymon Guz <mabewlun(at)gmail(dot)com>
Cc: Karina Guardado <kguardado(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: find a string contained in an attribute
Date: 2010-03-25 07:34:09
Message-ID: 162867791003250034v526f58d3wffc26d1d4f1df073@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2010/3/24 Szymon Guz <mabewlun(at)gmail(dot)com>:
> 2010/3/24 Karina Guardado <kguardado(at)gmail(dot)com>
>>
>> Hi,
>>
>> I want to know if it is possible to search for a string of characters
>> inside an attribute for example I have the following table and values
>>
>> cod_unidad |                 nombre_uni
>> ------------+---------------------------------------------
>>           1 | Facultad de Ciencias Naturales y Matemática
>>           2 | Facultad de Ciencias Humanidades
>>           3 | Facultad de Ingeniería
>>           4 | Facultad de Agronomía
>>           5 | Oficinas Centrales
>>           6 | test
>>
>>
>> I want to retrieve all the rows where I find the word Ciencias for
>> example. Is there a function or with select is possible to do it?
>>
>> thanks in advance,
>>
>> karina
>> El Salvador, Centroamerica
>
> For example something like this should work:
> SELECT * FROM table WHERE nombre_uni like '%Ciencias%';
> more you can find
> here: http://www.postgresql.org/docs/8.4/interactive/functions-matching.html
> regards
> Szymon Guz

better to use a fulltext it is much faster on tables larger than small

create index foo on tab using gin(to_tsvector('simple', nombre_uni))

select * from tab where to_tsvector('simple', nombre_uni) @@
to_tsquery('simple', 'Ciencias');

Regards
Pavel Stehule

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Yan Cheng CHEOK 2010-03-25 07:49:52 Side effect of synchronous_commit = off
Previous Message Frans Hals 2010-03-25 06:36:01 Re: Large index operation crashes postgres