0

I am running this query:

Select column_name
from table
where column_name ~ '%[A-Za-z]%'
group by column_name

but I am not getting any results. What am I doing wrong?

Goal: This is a column that includes phone numbers. I am trying to find any values that contain string characters.

I don't understand why ilike does not support regex This is what I found here

The operator ~~ is equivalent to LIKE, and ~~* corresponds to ILIKE. There are also !~~ and !~~* operators that represent NOT LIKE and NOT ILIKE, respectively. All of these operators are PostgreSQL-specific.

Doesn't this mean I can use ilike by using ~~*?

Edit: What I have learned so far

  1. Don't use like, use tilda.
  2. Where column_name ~ '%[A]%'
  3. Where column_name ~ $$[A]$$ does work.

Theory: It has something to with the dollar signs or the apostrophe. Result: It was the % signs.

2
  • 2
    ILIKE doesn't support regex - it only supports the wildcards that LIKE supports. If you want regex use the ~ operator. See the manual for details: postgresql.org/docs/current/static/… Commented Oct 6, 2016 at 15:04
  • Thanks. I edited my post to reflect what I am doing now. Commented Oct 6, 2016 at 15:09

1 Answer 1

1

According to RegexBuddy, the correct syntax for the WHERE clause is:

WHERE mycolumn ~ $$[A-Z]$$
Sign up to request clarification or add additional context in comments.

2 Comments

It worked!!!! I typed the query incorrectly from what you gave me, my mistake. I left the % signs in.
If lower case characters are an issue, use ~ '[A-Za-z]' to find anything that contains non-digits, use ~ '[^0-9]'

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.