mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-24 19:38:24 +00:00
Correctly compare numeric field values
This commit is contained in:
@ -0,0 +1,12 @@
|
||||
DROP ALIAS IF EXISTS CAST_TO_NUMERIC;
|
||||
CREATE ALIAS CAST_TO_NUMERIC AS '
|
||||
import java.text.*;
|
||||
import java.math.*;
|
||||
@CODE
|
||||
BigDecimal castToNumeric(String s) throws Exception {
|
||||
try { return new BigDecimal(s); }
|
||||
catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
'
|
@ -0,0 +1,5 @@
|
||||
-- Create a function to cast to a numeric, if an error occurs return null
|
||||
-- Could not get it working with decimal type, so using double
|
||||
create or replace function CAST_TO_NUMERIC (s char(255))
|
||||
returns double deterministic
|
||||
return cast(s as double);
|
@ -0,0 +1,9 @@
|
||||
-- Create a function to cast to a numeric, if an error occurs return null
|
||||
create or replace function CAST_TO_NUMERIC(text) returns numeric as $$
|
||||
begin
|
||||
return cast($1 as numeric);
|
||||
exception
|
||||
when invalid_text_representation then
|
||||
return null;
|
||||
end;
|
||||
$$ language plpgsql immutable;
|
Reference in New Issue
Block a user