我可以通过lib / pq Go SQL驱动程序获得EXPLAIN ANALYZE输出吗?

I'd like to be able to evaluate my queries inside my app, which is in Go and using the github.com/lib/pq driver. Unfortunately, neither the [lib/pq docs][1] nor the [database/sql][2] docs seem to say anything about this, and nothing in the database/sql interfaces suggests this is possible.

Has anyone found a way to get this output?

Typical EXPLAIN ANALYZE returns several rows, so you can do it with simple sql.Query. Here is an example:

package main

import (
    "database/sql"
    "fmt"
    _ "github.com/lib/pq"
    "log"
)

func main() {
    db, err := sql.Open("postgres", "user=test dbname=test sslmode=disable")
    if err != nil {
        log.Fatal(err)
    }

    defer db.Close()

    rows, err := db.Query("EXPLAIN ANALYZE SELECT * FROM accounts ORDER BY slug")
    if err != nil {
        log.Fatal(err)
    }

    for rows.Next() {
        var s string
        if err := rows.Scan(&s); err != nil {
            log.Fatal(err)
        }
        fmt.Println(s)
    }
    if err := rows.Err(); err != nil {
        log.Fatal(err)
    }
}