Re: Can I search for an array in csf? - Mailing list pgsql-sql

From Vernon Wu
Subject Re: Can I search for an array in csf?
Date
Msg-id HFONZXTRQRQBWVCA3YGEMJ7108PJ4Y.3db53187@kimiko
Whole thread Raw
In response to Can I search for an array in csf?  (Vernon Wu <vernonw@gatewaytech.com>)
List pgsql-sql
Hi, Christoph,

Thanks for reminding me regular expression. 

The background of my question is about attributes of one element, say hobby for example. Different people have 
different hobbies. Inside of the application, hobbies are denoted in various characters. The selection I mentioned in
the
 
original mail refers to finding people who have certain hobbies in the case.

I think regular expression is the most effective way for the usage.

Thanks again.

Vernon


10/22/2002 5:50:22 AM, Christoph Haller <ch@rodos.fzk.de> wrote:

>>
>> I thought I had made my case clear. Let me rephrase it.
>>
>> I have a character array, {'a', 'b', 'c', 'd'} for example. And this
>array is stored in a DB table field as a string
>of "a,b,c,d".
>> Now, I want to find out whether the table field, or array, contains
>any character set of {'c', 'e', 'h'}. My question
> is
>> whether SQL statement is appliable for this selection, or the data has
>been retrieved and process in the application
>> level.
>>
>> I hope I make th case clear this time.
>>
>Ok, now I see.
>Maybe the Postgres POSIX Regular Expressions are what you are looking
>for.
>Suppose your array "a,b,c,d" is stored into a table field of type
>character,
>character varying or text.
>Then, if you are searching for all entries containing a 'c', 'e',  or
>'h' character
>your SELECT statement would look like
>
>SELECT col1, col2, ... FROM table1 WHERE arrayfield ~ '[ceh]' ;
>
>Still not sure if you mean a sequence like "c,e,h" on the other hand.
>Then
>SELECT col1, col2, ... FROM table1 WHERE arrayfield ~ 'c,e,h' ;
>should do the trick - as long as the order of characters is identical.
>A sequence of "e,c,h" would not show up, of course.
>
>Regular Expressions are far more powerful than these two examples can
>show.
>Refer to the related chapter in the documentation.
>I hope this helps more than the other replies you've received telling
>you
>'Learn about DB-design first'.
>
>Regards, Christoph
>
>





pgsql-sql by date:

Previous
From: "Josh Berkus"
Date:
Subject: Re: Can I search for an array in csf?
Next
From: Stephan Szabo
Date:
Subject: Re: 'fake' join and performance ?