0

I have a table that contains the following three rows

                     name                     
----------------------------------------------
 user - help center test 4 [120,2010-08-19]
 test - help center test 2 [123,2010-01-19]
 help center test [20109,2010-01-01]
(3 rows)

Now i need to get a exact match of "help center test" thus it should return the 3rd row. I basically need to do this exact match as if [20109,2010-01-01] does not exist in help center test [20109,2010-01-01] thus eliminating the brackets and everything within the brackets. NOte the result within the bracket could be anything.

If the brackets weren't there I would use something like SELECT name FROM clients WHERE lower(name) like '%call center test%' and that would give me the result but now I need to do the same with the above results? Is this possible?

1 Answer 1

1

According to: http://www.postgresql.org/docs/8.1/static/functions-matching.html :

SELECT name FROM clients WHERE name ~* 'help center test \\[.*?\\]'

Just to clarify that the ~* is a case insensitive match, so there's no need for the lower() function call on the name. This will match all rows that start "help center test [" then have n characters and finally end with "]" (both without double quotes, of course).

Sign up to request clarification or add additional context in comments.

2 Comments

~ is case sensitive, it did not give me correct results without lower but when I added it in it worked perfectly, thanx alot for this answer, much appreciated. Maybe the case sensitive has somehing to do with my old postgres version 8.1.22 . Thx again
Sorry - my bad. Fixed accordingly - you should actually use ~* for case insensitivity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.