从特定列
问题描述:
我在,我想找到节数在特定列小数一个表,我只是想获得其中有超过2位小数从特定列
我记录查找节数小数我想这一点:
SELECT amount
FROM fin_payment_scheduledetail where amount ilike '%._____'
错误:
operator does not exist: numeric ~~* unknown
答
从你的错误,我看到的数字数据类型,因而例如:
t=# with f(l) as (values(3.092::numeric),(0),(0.2),(9.000))
select l,position('.' in l::text),char_length(l::text), char_length(l::text)-position('.' in l::text) dug2more from f;
l | position | char_length | dug2more
-------+----------+-------------+----------
3.092 | 2 | 5 | 3
0 | 0 | 1 | 1
0.2 | 2 | 3 | 1
9.000 | 2 | 5 | 3
(4 rows)
9.000
被认为具有点后3位数字,这在数学上就错了(COS其不是三 - 其零,或三个或42 - 所有这些是不相等的产品总数,从而说这是三是无义)
从而为arythmetics的缘故,我想补充一个更明确的转换:
t=# with f(l) as (values(3.092::numeric::float),(0),(0.2),(9.000))
select l,position('.' in l::text),char_length(l::text), char_length(l::text)-position('.' in l::text) dug2more
from f;
l | position | char_length | dug2more
-------+----------+-------------+----------
3.092 | 2 | 5 | 3
0 | 0 | 1 | 1
0.2 | 2 | 3 | 1
9 | 0 | 1 | 1
(4 rows)
,最后就用正则表达式:
t=# with f(l) as (values(3.092::numeric),(0),(0.2),(9.000))
select l,l::text ~ '\d{1,}.\d{2,}' from f;
l | ?column?
-------+----------
3.092 | t
0 | f
0.2 | f
9.000 | t
(4 rows)
正如你所看到的,在9.000的情况下比较是正确的。所以它取决于你在这里想要什么 - 算术的语义检查