I want to make a function in PostgreSQL that would make the following:
First of all read some data from a table lets say “Select col1,col2 from table1” Then for each row of the above selection I want to make an insert to an other table lets say table2 (that contains some extra columns like date and so on).
For each insertion I want a unique key that starts from a given number and is increased in every new row. Can someone give me an example about how I can do it?
I need to be more specific I want to do what is discribed below:
For(every row in table1)
if(table1.col1>0)
insert into table2 (c1,c2,c3,c4) nalues (id,table1.col1,table1.col2,'oposite',current_timestamp)
else if(table1.col1<0)
insert into table2 (c1,c2,c3,c4) nalues (id,table1.col1,table1.col2,'negative',current_timestamp)
id+=1