Using Vim for SQL
We recently had a discussion on the team about good SQL editors for Postgres. And we quickly discovered that nobody really liked what they were using. I have been using Razor SQL until now, but it is quirky and I have never used any of the advanced features.
So as an experiment I am now using Vim to edit SQL, because I’m already using it for lots of other stuff and I’m very comfortable with it.
Vim has decent syntax highlighting and very basic indentation support for SQL.
If the filetype is not detected from the filename, use :set ft=sql
to set
it.
To have the current buffer executed through psql
, I configured this key binding:
map <leader>S :w !psql gomore_development<cr>
It is working really well so far. Nice to be using a good text editor, and the
ouput from pqsl
is of course nicely formatted.
Related tip: When working with very wide tables and few rows at a time, it can be helpful to enable “expanded output”:
\x on
select * from users limit 2