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:
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')