0

I have following column in Postgres table. I would like to only get values where there are multiple words in a string.

col1
nilotinib hydrochloride
ergamisol
ergamisol
methdilazine hydrochloride

The desired output is

col1
nilotinib hydrochloride
methdilazine hydrochloride

I am using following pattern to extract the strings but it's not working

SELECT regexp_match(col1, '^\w+\s+.*') from tb1;
1
  • Can you show us the full SQL query that you're using, please? Commented Apr 11, 2022 at 19:37

1 Answer 1

1

To filter rows, use a WHERE clause in your statement:

SELECT col1
FROM tb1
WHERE col1 ~ '^\w+\s+.*';

See the string matching documentation for alternatives to your pattern. For your case, col1 ~ '\s' should be sufficient, or col1 SIMILAR TO '%[[:space:]]%'.

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

Comments

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.