Postgres查询以检查字符串是否为数字 [英] Postgres query to check a string is a number

查看:1072
本文介绍了Postgres查询以检查字符串是否为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我该查询以检查字符串是否为数字(双精度)。如果字符串是数字,则应返回true。



<考虑>:

  s1个字符变化; 
s2字符变化;

s1 = 12.41212 =>应该返回true
s2 =服务 =>应该返回false


解决方案

我认为最简单的方法是正则表达式匹配:

 选择'12 .41212'〜'^ [0-9\。] + $'
=> true

选择服务〜‘^ [0-9\。] + $’
=>假


Can anyone tell me the query to check whether a string is a number(double precision). It should return true if the string is number. else it should return false.

consider :

       s1 character varying;
       s2 character varying;

       s1 ='12.41212' => should return true
       s2 = 'Service' => should return false

解决方案

I think the easiest way would be a regular expression match:

select '12.41212' ~ '^[0-9\.]+$'
=> true

select 'Service' ~ '^[0-9\.]+$'
=> false

这篇关于Postgres查询以检查字符串是否为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆