Skip site navigation (1) Skip section navigation (2)

Re: select from pipe-delimited field

From: san man <neelakash21(at)gmail(dot)com>
To: Arjen Nienhuis <a(dot)g(dot)nienhuis(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org
Subject: Re: select from pipe-delimited field
Date: 2010-08-23 23:07:08
Message-ID: AANLkTimxgCziuLxQhyJQg7jELM=fF8Gqeh8mo759EeZf@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-novice
Thanks for the replies.
David, I would have normalized it to 2 or more tables, but the number of
bar-delimited are not fixed and as new data are added the maximum number of
these values may change. Also, the problem with like I think is that
matching is not strict and thus might give spurious hits.

Arjen's solution(haven't tried yet) looks better to me.

-Neel

On Mon, Aug 23, 2010 at 5:59 PM, Arjen Nienhuis <a(dot)g(dot)nienhuis(at)gmail(dot)com>wrote:

> On Tue, Aug 24, 2010 at 12:44 AM, san man <neelakash21(at)gmail(dot)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
>>
>
>

In response to

Responses

pgsql-novice by date

Next:From: Craig RingerDate: 2010-08-24 02:21:54
Subject: Re: select from pipe-delimited field
Previous:From: Arjen NienhuisDate: 2010-08-23 22:59:40
Subject: Re: select from pipe-delimited field

pgsql-general by date

Next:From: Mike ChristensenDate: 2010-08-23 23:38:22
Subject: Re: Npgsql Exception
Previous:From: Arjen NienhuisDate: 2010-08-23 22:59:40
Subject: Re: select from pipe-delimited field

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group