I have the following code:
selectPart := "id, user_id, date, time, minutes, details, created_at, updated_at, project_id"
sqlQuery := fmt.Sprintf("SELECT %s FROM time_entries WHERE user_id = $1 AND date >= $2 and date <= $3", selectPart)
var rows *sql.Rows
var err error
if project == nil {
rows, err = DB.Query(sqlQuery, user.ID, formatDate(from), formatDate(to))
} else {
rows, err = DB.Query(sqlQuery + " AND project_id = $4", user.ID, formatDate(from), formatDate(to), project.ID)
}
The resulting rows structure is empty. I suppose it is because the interpolation of data is wrong. I am using PostgreSQL. Can I somehow get an SQL string from the rows
instance?