0

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.

1 Answer 1

2
UPDATE tableName
SET multi = id * number;

Or am I missing something?

Sign up to request clarification or add additional context in comments.

3 Comments

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"
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 UPDATE public.edge_table1 SET start_geom = ST_StartPoint(ST_Force2D(geom));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.