Store numbers in a numeric field, integer, decimal, or any other. But not in the text / varchar field.
Check the manual for all numeric data types .
Unpleasant workaround: CAST some entries to a numeric value and save others as text. Example:
WITH cte AS (
SELECT
CASE
WHEN x ~ '[0-9]' THEN CAST(x AS decimal)
END AS num,
CASE
WHEN x ~ '[a-zA-Z]' THEN x
END AS a
FROM foo
)
SELECT AVG(num), COUNT(a) FROM cte;
source
share