2017-09-26 120 views
1

我在,我想找到節數在特定列小數一個表,我只是想獲得其中有超過2位小數從特定列

我記錄查找節數小數我想這一點:

SELECT amount  
FROM fin_payment_scheduledetail where amount ilike '%._____' 

錯誤:

operator does not exist: numeric ~~* unknown

回答

0

從你的錯誤,我看到的數字數據類型,因而例如:

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的情況下比較是正確的。所以它取決於你在這裏想要什麼 - 算術的語義檢查