Re: How to search ignoring spaces and minus signs

From: Joshua Berry <yoberi(at)gmail(dot)com>
To: Andrus <kobruleht2(at)hot(dot)ee>, PostgreSQL - General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to search ignoring spaces and minus signs
Date: 2010-10-14 02:41:38
Message-ID: AANLkTinC95uQ_-dkYanv82_bajnS_AKS9mGdrn68ukSG@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Andrus,

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.
>

Check out
http://www.postgresql.org/docs/8.4/interactive/functions-string.html and try
using these functions to modify the comparison in the WHERE portion of a
query.
For example, if the CHAR(20) column that you mentioned is called 'sku' and
the user enters a value like '12345'

select * from table where replace(replace(sku, ' ', ''), '-', '') = '12344'

-Joshua

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2010-10-14 03:34:53 Re: pitr question
Previous Message Gauthier, Dave 2010-10-14 02:28:39 Re: Adding a New Column Specifically In a Table