0

I'm using the Echo web framework. One of the requests I need it to handle is to query an pgsql and return the data in CSV format. https://echo.labstack.com/guide/response I believe it would be something like:

func(c echo.Context) (err error) {
  data := []byte(//the CSV formated data??)
    return c.Blob(http.StatusOK, "text/csv", data)
}

The thing is I couldn't find a great way to query the db and get the data in CSV format 64byte encoded. The closest I could find is the package sqltocsv https://github.com/joho/sqltocsv but I couldn't make it work.

Is there a nice and clean way to do it?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
O. San
  • 1,107
  • 3
  • 11
  • 25
  • Please include the code you've tried, and explain the problem you're having. – Jonathan Hall May 20 '19 at 13:51
  • In case of copy command in psql you have file saved (or stdout populated) first and then you read it. You can use any driver (even pure one ```github.com/lib/pq```) and do smth like ```db.Exec(fmt.Sprintf("copy users to '/tmp/users.csv' with csv header"))``` or ```db.Exec(fmt.Spintf("copy users to stdout (delimiter '|')")``` – Sergey Narozhny May 20 '19 at 20:04

0 Answers0