0

I currently I have Vim set up with the dbext plugin to run queries against a database. After running a query, it creates a new buffer for the output results.

So far, this setup works okay if I just want to see the output of a query, but instead I want to write the query output to a CSV file so that I can use it elsewhere.

Is there a good way to do this?

I found that if I go to the buffer and say :w filename I can save the output as a file, but the problem is that the default output from dbext isn't formatted like a proper CSV file.

bobfet1
  • 1,603
  • 21
  • 22

1 Answers1

1

If your DB is PostgreSQL, then you can wrap your query in e.g.

COPY (<put-query-here>) TO STDOUT WITH (FORMAT CSV);

I believe there are similar solutions for other DBs.

Sebastian
  • 8,046
  • 2
  • 34
  • 58