Find from a text if there is more than 6 consecutive number

时间:2018-09-18 20:23:36

标签: sql postgresql text

I am trying to select from the following column text all those rows which have more than 6 consecutive numbers

  id                    text
   1         Hi how are you?
   2     my number 156784043
   3             Lucas Dresl
   4                34856708
   5         Collin Ave. 543 
   6                Mate man
   7      How much for this?

my expected result is just to have a select or count of how many rows fulfill the condition of 6 consecutive numbers or more

  id                    text
   2     my number 156784043
   4                34856708

or

 count_id
        2

1 个答案:

答案 0 :(得分:2)

Here's one option using regexp:

select count(*)
from yourtable
where yourfield regexp '[0-9]{6}'

Since you are using postgresql instead of mysql, use ~ instead:

select count(*)
from yourtable
where yourfield ~ '[0-9]{6}'