Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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.

share|improve this question
UPDATE tableName
SET multi = id * number;

Or am I missing something?

share|improve this answer
    
I tried this but I don't know why it is not working, it is giving "Error: more than one row returned by a subquery used as an expression" – LSG Dec 10 at 22:31
    
@LSG How exactly are you running this code? – melpomene Dec 10 at 22:33
    
Ok, I have geometry data with column name geom. I want to fill start_geom column from geom column by using ST_startpoint. My query is: UPDATE public.edge_table1 SET (start_geom)= (SELECT ST_StartPoint(ST_Force2D(geom)) FROM public.edge_table1); – LSG Dec 10 at 22:53
    
@LSG UPDATE public.edge_table1 SET start_geom = ST_StartPoint(ST_Force2D(geom)); – melpomene Dec 10 at 22:55
    
Ok, thanks. It is working. – LSG Dec 10 at 23:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.