Search Postgresql Archives

Re: Regular expression. How to disable ALL meta-character

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Apr 21, 2005 at 09:03:43AM -0400, David Gagnon wrote:
> 
> Just want to share the solution I got to solve my problem. I wanted to 
> be eable to search a string (say X) (non case sensitive) without having 
> meta-character involved.  The X string come directy from the web so any 
> [%]* may cause error in regular expression (because they form non valid 
> expression)
> 
> 1) Using like: select * from mytable where lower(mycol) LIKE lower("%" 
> || lower(X) || "%");
> Mostly perfect solution.  Don't crash but % still have a special 
> meaning. Wich means anything

Have you considered using position() or strpos()?  They do simple
substring searches without any metacharacters.

SELECT position(lower('AbC') in lower('aBcDeF'));
 position 
----------
        1
(1 row)

SELECT position(lower('xYz') in lower('aBcDeF'));
 position 
----------
        0
(1 row)

You might also want to look at the contrib/pg_trgm module to see
if it would be useful.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux