Golang如何使用sql查询行检查错误

I am using postgres database and am returning a Json response from the database in the form of a string which is used for an API . My problem is that I do not know how to check for errors using the QueryRow Method . This right here is my code and it works correctly. That just shows a Json response . However I have a custom function that I would like to use if there is some error with the code and QueryRow does not let me check for errors any suggestions ?

 var result string
 db.QueryRowContext(ctx,"select json_build_object('Profile', array_to_json(array_agg(t))) from" +
                    " (select p.id,p.fullname,z.thirtylatmin as latmin,z.thirtylatmax as latmax,z.thirtylonmin as lonmin," +
                          "z.thirtylonmax as lonmax,p.latitudes,p.longitudes,p.location as location" +
                    ",p.picture,p.is_gold from profiles p join zips z on (z.city='Boston' " +
                 "and z.state='MA') where email=$1) t;",email).Scan(&result)

io.writestring(w, result)

If I change the above code to this then it works with the error message however how can I return that in a String

SqlStatement,err := db.QueryContext(ctx,"select json_build_object('Profile', array_to_json(array_agg(t))) from" +
                " (select p.id,p.fullname,z.thirtylatmin as latmin,z.thirtylatmax as latmax,z.thirtylonmin as lonmin," +
                      "z.thirtylonmax as lonmax,p.latitudes,p.longitudes,p.location as location" +
                ",p.picture,p.is_gold from profiles p join zips z on (z.city='Boston' " +
             "and z.state='MA') where email=$1) t;",email)

            if err != nil {
                log_errors("sql statement error",err.Error(),w)
            }
            io.WriteString(w, "How can I get SqlStatement as 1 whole String ??")

The statement above lets me log any errors and insert it into the database, now how can I get SqlStatement to return as 1 whole string ? The SQL statement returns perfectly now I just need to get it into io.WriteString in a String format

You should just check return value of Row.Scan method, just like this:

row := db.QueryRow(
    `SELECT 
        json_build_object('Profile', array_to_json(array_agg(t))) 
    FROM
        (
            SELECT 
                p.id,
                p.fullname,
                z.thirtylatmin as latmin,
                z.thirtylatmax as latmax,
                z.thirtylonmin as lonmin,
                z.thirtylonmax as lonmax,
                p.latitudes,
                p.longitudes,
                p.location as location,
                p.picture,
                p.is_gold 
            FROM 
                profiles p 
            JOIN zips z on (z.city='Boston'AND z.state='MA') 
            WHERE 
                email=$1
        ) t`,
    email,
)

var result string
if err := Scan(&result); err != nil {
    log.Fatal(err)
}

fmt.Fprint(w, result)