Re: Can I search for an array in csf?

From: Vernon Wu <vernonw(at)gatewaytech(dot)com>
To: Christoph Haller <ch(at)rodos(dot)fzk(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Can I search for an array in csf?
Date: 2002-10-22 11:07:51
Message-ID: HFONZXTRQRQBWVCA3YGEMJ7108PJ4Y.3db53187@kimiko
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)rodos(dot)fzk(dot)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
>
>

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2002-10-22 12:51:47 Re: Row Locking?
Previous Message Vernon Wu 2002-10-22 10:54:56 Re: Fwd: Re: Can I search for an array in csf?