Re: How to search ignoring spaces and minus signs

From: Josh Kupershmidt <schmiddy(at)gmail(dot)com>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to search ignoring spaces and minus signs
Date: 2010-10-13 22:37:52
Message-ID: AANLkTimDBrFrSkGrsMMWwmNM3Yd9zzaDhvdMw=3=4h7U@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2010/10/13 Andrus <kobruleht2(at)hot(dot)ee>:
> CHAR(20) columns in 8.4 database may contains spaces and - signs like
>
> 13-333-333
> 12 3-44
> 33 33 333
> 12345
>
> User enters code to search without spaces and - signs, like 12344
> How to search for product code ignoring spaces and - signs?
>
> For example searching for code 12344 should return
> 12 3-44  as matching item.

How about using translate() to strip off dashes and spaces:
SELECT mycol FROM mytable
WHERE translate(mycol, '- ', '') = '12344';

Josh

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Christian Ramseyer 2010-10-14 01:24:12 Re: How to search ignoring spaces and minus signs
Previous Message Raymond O'Donnell 2010-10-13 22:36:18 Re: Adding a New Column Specifically In a Table