Postgres SQL state: 22P02
Apparently conversion_units
is a string which can hold values not convertible to numeric
.
You immediate problem can be solved this way:
SUM(NULLIF(conversion_units, '')::numeric)
but there can be other values.
You might try to use regexp to match convertible strings:
SUM((CASE WHEN conversion_units ~ E'^\\d(?:\\.\\d)*$' THEN conversion_units END)::numeric)
For future searchers:
I got this error (Postgres SQL state: 22P02) while trying to import data from csv.
with this command:
COPY my_end_table FROM 'D:\check\sample.csv' WITH CSV
Solution: turns out the csv should not contain headers....