0

Suppose my column name is "psdi", i want to print only numeric rows

psdi
100
10k
103f
456
9o2u
125
931

Required O/P:

psdi
100
456
125

2 Answers2

2

Here are two simple methods. One looks for letters:

select t.*
from t
where not psdi ~ '[a-zA-Z]'

or for just digits:

select t.*
from t
where not psdi ~ '^[0-9]+$'
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

Use pattern matching in where clause

'^-?([0-9]+\.?[0-9]*|\.[0-9]+)$' - This selects all type of values(positive, negative and floating values)

select *
from (
    values ('100T')
          ,('456.5')
          ,('-65')
          ,('9879t')
          ,('454')
    ) t(a)
where a ~ '^-?([0-9]+\.?[0-9]*|\.[0-9]+)$'

demo


Your query will be

select psdi
from your_table
where psdi ~ '^-?([0-9]+\.?[0-9]*|\.[0-9]+)$'
Vivek S.
  • 19,945
  • 7
  • 68
  • 85