Re: BUG #3506: to_number silently ignore characters - Mailing list pgsql-bugs

From William Leite Araújo
Subject Re: BUG #3506: to_number silently ignore characters
Date
Msg-id bc63ad820708030755s7ab28051i63b4dc64b5db9e5c@mail.gmail.com
Whole thread Raw
In response to Re: BUG #3506: to_number silently ignore characters  ("William Leite Araújo" <william.bh@gmail.com>)
List pgsql-bugs
   Ok. Now the function is OK....<br /><br /><span style="font-weight: bold;">CREATE OR REPLACE FUNCTION</span>
my_to_number(text,text)<span style="font-weight: bold;">RETURNS</span> numeric <span style="font-weight: bold;">AS
</span><br/>$$ <br />    <span style="font-weight: bold;">BEGIN</span>  <br />        <span style="font-weight:
bold;">IFNOT </span>textregexeq($1,'^[0-9]+$') <span style="font-weight: bold;">THEN</span>  <br />               
<spanstyle="font-weight: bold;">RAISE EXCEPTION</span> 'TEXT % is not a valid NUMBER',$1; <br />        <span
style="font-weight:bold;">END IF;</span><br />        <span style="font-weight: bold;">RETURN</span> to_number($1,$2);
<br/><span style="font-weight: bold;">    END;</span><br />$$ <span style="font-weight: bold;">LANGUAGE PLPGSQL
IMMUTABLE;<br/><br /></span>Tests...<br /><br />=# select my_to_number('123.0','999999');<br />ERRO:  TEXT 123.0 is not
avalid NUMBER<br />=# select my_to_number('1230','999999');<br /> my_to_number<br />--------------<br />        
1230<br/>(1 registro)<br /><br />Tempo: 0,734 ms<br /><br />-- <br />William Leite Araújo<br />DBA - QualiConsult <br
/>

pgsql-bugs by date:

Previous
From: "William Leite Araújo"
Date:
Subject: Re: BUG #3506: to_number silently ignore characters
Next
From: Rodriguez Fernando
Date:
Subject: Re: Bug Pgsql