Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extract strings with multiple words in Postgres 11.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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT regexp_match(col1, '^\w+\s+.*') from tb1;

>Solution :

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:]]%'.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading