[beginner]
I have a table that looks like this:
colA colB
1 <null>
2 <null>
3 <null>
colB
is the new empty column I added to the table. colA
is varchar and colB
is double precision data type (float).
I want to update colB
with a colA
multiplied by 2.
New table should look like this:
colA colB
1 2
2 4
3 6
When I go to update colB
like so:
update tablename set colB = colA * 2
I get error:
Invalid operation: Invalid input syntax for type numeric
Ive tried to work around this with solutions like this:
update tablename set colB = COALESCE(colA::numeric::text,'') * 2
but get the same error.
In a select statement on the same table, this works on colA
which is varchar:
select colA * 2 from tablename
How can I update a column with mathematical operations with different datatype reference columns? I cant update datatype for colA
.