Installation

Additionally, the script itself relies on the command line clients of the various DBMSes that it supports. For dbext to work, refer to the table below and make sure that the binary appropriate for the system you'd like to work with is available. Often these clients are bundled with the DBMS itself, but otherwise should be available through your favorite package manager.

Required command line client binaries for each DBMS supported by dbext

The \se (s SQL, e execute) command is useful for multiline queries. It searches backwards for the beginning of a query by looking for certain SQL command keywords (e.g. SELECT) and searches forwards for the end of a query by looking for your connection's command terminator (e.g. ;). For example, the following SQL should execute with \se no matter where your cursor is on it:

select *
from user
limit 100;

\st selects everything from the table whose name is under your cursor (e.g. user in the previous example).

\sT selects from the table under your cursor, but prompts for the number of rows to select. This is a much safer alternative to \st when working with a lot of data.

\stw selects from the table under your cursor, but prompts for a where clause (don't include the keyword WHERE).

\sdp is very similar, but instead describes the stored procedure under your cursor.

The three command directives :DBListTable, :DBListProcedure, and :DBListView list the database's tables, stored procedures, and views respectively. I find it useful to map the table list to its own key:

map <leader>l :DBListTable<CR>

\slc copies each of the column names in the table under your cursor to the unnamed register in a format like userID, username. This is useful for constructing select queries on tables.

The Results Buffer

There are a few useful shortcuts specific to when your cursor is in the results buffer.

R will re-run the command which populated the current results.

q will quickly close the results.

Summary

Recall that this article was written to be a very minimal introduction to dbext to highlight what are (in my opinion) some of its most useful features. Refer to dbext's excellent documentation to discover its full potential.

Posted on May 3, 2011 from Calgary

Newest Articles

About

My name is Brandur. I'm a polyglot software engineer and part-time designer working at Heroku in San Francisco, California. I'm a Canadian expat. My name is Icelandic. Drop me a line at [email protected].

Aside from technology, I'm interested in energy and how it relates to our society, travel, longboarding, muay thai, symphonic metal, and the guitar.