Filter strings with regex before casting to numeric
问题 I have this code (was already there, isn't mine): SELECT a.id_original_contrato AS contrato, ( CASE WHEN d.value~'^\\d+$' THEN d.value::integer ELSE 0 END ) AS monto, EXTRACT(YEAR FROM b.value)::integer AS anoinicio, EXTRACT(YEAR FROM c.value)::integer AS anofin ... etc (some JOIN's and WHERE's) Let me explain: d.value comes from a table where value is character varying (200) . The code will insert later the d.value (now called 'monto') in another table as a integer . Someone coded that regex