Postgresql – Update column with the value of two columns multiplied

postgresqlupdate

I want to update ColumnA with the value of ColumnB x ColumnC. Can someone please help? I have tried the following:

UPDATE database.table
SET ColumnA = ColumnB * ColumnC;

Error message as follows:

ERROR: operator does not exist: double precision * character varying
LINE 2: SET ColumnA = ColumnB * ColumnC;
^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
SQL state: 42883 Character: 58

Best Answer

Text values must be converted to numeric before any math operation.

UPDATE schema.table
SET    ColumnA * ColumnC::numeric  -- Use same data type as ColumnA

Have a look at this tutorial