Given a file which consists of multiple line MySQL queries, eg
SELECT foo, bar, etc
FROM blah
WHERE something or other
LIMIT etc
Is there any way I can visually select a query in Vim, pipe it through MySQL, and see the query and result in a new buffer?
Clarification: I don’t want tabular output, but something that can be further processed in vim or imported into a spreadsheet (like the tab-separated output that you get from mysql –batch)
(Ubuntu Linux).
The
Dbextplugin supports this behavior.Visually select the SQL statement, and run
:DBExecRangeSQLto execute it.The result will be returned into a new split at the bottom of your current viewport.
There are lots and lots of options for controlling the output window. See
:help dbextfor the glorious details.Update 1.May.2012
Version 15.0 of the plugin has been released with this functionality built in.
The default
-tflag can be overriddenDefault setting:
Overridden for batch setting
Dbext hard-codes the-toption to MySQL, but if that line is removed from dbext.vim, on line 2278 in DB_MYSQL_execSql (of my current version), you can pass the –batch and –raw options:To restore tabular output:
I tested this successfully on my installation.