Reputation: 223
I have following columns and data set to my table. I need to fill the multi column as id*number (i.e. the first value in multi column would be 1*1025=1025, second value would be 2*2587=5174 and so on. I need a postgresql query for this. Do I need a for loop or can be done by some other trick (but I don't want to do it one by one column instead of doing altogether)?
id multi number
1 1025
2 2587
3 1475
4 5698
5 254
6 912
7 442
8 8756
9 1123
Then I have got the following query is the simplest way
SELECT
id,
number,
(id * number) as multi
FROM
tableName
This SELECT is working but INSERT or UPDATE is not working with this.
Upvotes: 0
Views: 166
Reputation: 85767
UPDATE tableName
SET multi = id * number;
Or am I missing something?
Upvotes: 2