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

Extracting 8 numbers after several prefixes in where clause in postgres

I am trying to select data in postgres, where 8 numbers after some particular prefixes match given list of numbers. It works with one prefix, but with several I get NULL.

works:

select data  from table t 
where substring(data from '^3180(\d{8})') IN ('15042159','14438818')

does not work:

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 data  from table t 
where substring(data from '^(3180|3181)(\d{8})') IN ('15042159','14438818')

>Solution :

You can do it using non capturing group ?: :

select data 
from table t 
where substring(data from '^(?:3180|3181)(\d{8})') IN ('15042159','14438818')

Demo here

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