Extract numbers from a field in PostgreSQL
Simply: SELECT NULLIF(regexp_replace(po_number, ‘\D’,”,’g’), ”)::numeric AS result FROM tbl; \D being the class shorthand for “not a digit”. And you need the 4th parameter ‘g’ (for “globally”) to replace all occurrences. Details in the manual. For a known, limited set of characters to replace, plain string manipulation functions like replace() or translate() are substantially cheaper. … Read more