3

This is the table

chr
chr1
chr2
chr10
chrU_X
chrM_a_a

I want to get only chr%andnumber% (chr1, chr2,chr10 this case) with:

select chr
from varianti
where chr like 'chr_'
group by chr

But it returns only chr1 , chr2 not chr10.

I want to get the result like this:

chr 
chr1
chr2
chr10

Is there somethings wrong?

xCloudx8
  • 681
  • 8
  • 21

1 Answers1

2

You could use SIMILAR TO:

select *
from chr
where col similar to 'chr[0-9]*'

or a regular expression:

select *
from chr
where col ~ '^chr[0-9]*$'

please see a fiddle here.

fthiella
  • 48,073
  • 15
  • 90
  • 106
  • 2
    to get a bit more information about `LIKE` and `SIMILAR`in postgres look here: https://www.postgresql.org/docs/9.5/static/functions-matching.html – Nebi Sep 19 '16 at 07:38