Original post

Hi Everyone. I am falling into this error for sometime now and I am not able to fix it. I am trying to insert data into db after iterating thru an object with a simple insert statement. But when it hits the part where you insert the data into the database, it throws this error

//Error starts
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xd2c89f]

and other lines

//Error ends

The code snippet that i am using to insert the data into the db is as follows,

//code begins
for _, data := range Reportdata {
fmt.Println(“enter the loop…”)
err := repo.Db.QueryRow(“insert into savings_data (orgId,cid,bill_name,resource_id,usage_day,resource_type,total_hrs,total_ondem_hrs,total_ri_hrs,ondemand_rate,tot_res_cost,actual_ondem_cost,pot_ondem_hrs,pot_ondem_cost,saving,actual_saving,fee) values($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17) RETURNING id;”, orgID, data.ID, data.Name, data.ResourceID, data.Day, data.Type, data.TotalHrs, data.TotalOnDemandhrs, data.TotalRIHrs, data.OndemandRate, data.TotalResCost,
data.ActualOnDemandCost, data.PotentialOnDemandHrs, data.PotentialOnDemandCost, data.Saving, data.ActualSaving, data.Fee).Scan(&id)

        counter = counter + 1

//code ends

Here the Reportdata is an array of a struct that we have created and I am iterating thru the values that are found in it and inserting it into a db. I have tried several ways but I am not able to fix it. Any help on this will be greately appreciated.