0.2.4.1 mor statz

This commit is contained in:
Peder Vatn Austad
2024-05-26 21:30:40 +02:00
parent 4f01023df7
commit c41200c4a7

View File

@@ -20,7 +20,8 @@ func InsertOrUpdateEstimatedVehicleJourney(db *sql.DB, values []interface{}) err
operatorref = COALESCE(EXCLUDED.operatorref, estimatedvehiclejourney.operatorref),
vehicleref = COALESCE(EXCLUDED.vehicleref, estimatedvehiclejourney.vehicleref),
cancellation = COALESCE(EXCLUDED.cancellation, estimatedvehiclejourney.cancellation),
other = COALESCE(EXCLUDED.other, estimatedvehiclejourney.other);
other = COALESCE(EXCLUDED.other, estimatedvehiclejourney.other)
RETURNING CASE WHEN xmax = 0 THEN 'insert' ELSE 'update' END, id;
`
stmt, err := db.Prepare(query)
@@ -29,10 +30,14 @@ func InsertOrUpdateEstimatedVehicleJourney(db *sql.DB, values []interface{}) err
}
defer stmt.Close()
_, err = stmt.Exec(values...)
var action string
var id int
err = stmt.QueryRow(values...).Scan(&action, &id)
if err != nil {
return fmt.Errorf("error executing statement: %v", err)
}
fmt.Printf("Action: %s, ID: %d\n", action, id)
return nil
}