Postgresql – How to select values consisting of numerals only

postgresqlstring-searching

I have a column like this:

WW0476091
YA0457514
547856232
856987452
254785W11

I want to get the values that contain numerals only (decimal digits from 0 to 9). For the example above, I want only these records to be printed:

547856232
856987452

How can I do that?

Best Answer

You can use a regular expression for that:

select *
from the_table
where the_column ~ '^[0-9]+$';

Related question on Stackoverflow