Elisp Interface

Code by EricMarsden for a socket-level elisp interface to PostgreSQL.

If you don’t require a flashy interface and sophisticated programming language features this may be a good option. Otherwise near the same URL you can find a Common Lisp implementation of the same code, which has better exception handling support.

NicFerrier’s EmacsDb has a backend for PostgreSQL

emacs-module interface

With emacs25’s loadable modules, it’s possible to use postgresql’s client library directly. This is about four times faster than the pure elisp interface and supports more features (SSL, out-of-band transfer of parameters, etc)

There is a prototype implementation available here:

Info Documentation

You can convert Postgres’ DocBook docs to Texinfo via docbook2X for ultimate studying pleasure within Emacs. With 8.2, make in doc/src/sgml/ should automate this somewhat when you have docbook2X and toolchains for SGML, XML, and Texinfo installed.

Here’s how the result looks like with the 8.3.3 docs:

Using outline-minor-mode with SQL Dumps

I recently discovered that using outline-minor-mode is quite an elegant way to deal with vast SQL dumps. The following snippet will automatically set it up when visiting pg_dump output.

 (defun my-possibly-setup-pgdump-outline nil
     (goto-char (point-min))
     (forward-line 1)
     (when (looking-at "-- PostgreSQL database dump")
       (set (make-local-variable 'outline-regexp)
 	   "-- \\(Data for \\)?Name:")
       (set (make-local-variable 'outline-level)
 	   (lambda nil 1))
       (outline-minor-mode 1)
       (hide-sublevels 1))))
 (add-hook 'sql-mode-hook 'my-possibly-setup-pgdump-outline)

CategorySql CategoryDatabase