Re: [GENERAL] select from pipe-delimited field - Mailing list pgsql-novice

From Arjen Nienhuis
Subject Re: [GENERAL] select from pipe-delimited field
Date
Msg-id AANLkTikHkHuK4mddB33GaztkqEEZrrZiaN0+iz43LEZb@mail.gmail.com
Whole thread Raw
In response to select from pipe-delimited field  (san man <neelakash21@gmail.com>)
Responses Re: [GENERAL] select from pipe-delimited field  (san man <neelakash21@gmail.com>)
List pgsql-novice
On Tue, Aug 24, 2010 at 12:44 AM, san man <neelakash21@gmail.com> wrote:
Hello all,

I am trying to do a SELECT operation with a WHERE condition. However, the column with which I am trying to do the comparison has several values which are pipe-delimited. I want to return a match(true) if the WHERE condition matches any of the bar-delimited values.

For example, SELECT id WHERE synonyms = 'word';

Here synonyms is a pipe-delimited field and I want to match "word" with any of the values of the synonyms fields.


SELECT id FROM t WHERE 'word' = ANY(regexp_split_to_array(synonyms, '[|]'));
 
With postgres it's possible to make an index on regexp_split_to_array(synonyms, '[|]')) for some extra speed. But its better to store the synonyms as an array in the first place.

Thanks in advance.

Neel

pgsql-novice by date:

Previous
From: David Fetter
Date:
Subject: Re: [GENERAL] select from pipe-delimited field
Next
From: san man
Date:
Subject: Re: [GENERAL] select from pipe-delimited field