I need to select from a table a column that is supposed to be float. However, some values come up as string. Is thee a way to replace the string with a constant (say 999) within the select statement?
Thanks
I need to select from a table a column that is supposed to be float. However, some values come up as string. Is thee a way to replace the string with a constant (say 999) within the select statement?
Thanks
You may find useful answer here: https://stackoverflow.com/a/10307443/6359593 . I copied code here for lazy ones =)
create or replace function cast_to_int(text, integer) returns integer as $$
begin
return cast($1 as integer);
exception
when invalid_text_representation then
return $2;
end;
$$ language plpgsql immutable;