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
/>