Skip to content
Transform SQL statements (insert, update, delete) using Emacs Lisp
Emacs Lisp
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
sql-transform.el

README.md

SQL Transform

This code provides two things:

  1. INSERT, SELECT, UPDATE, and DELETE statements can be converted into each other: Place point within a SELECT statement and type M-x sql-to-update RET in order to transform the SELECT statement into an UPDATE statement.

  2. SQL statement pretty printer: Place point within a SELECT statement and type M-x sql-to-select RET in order to rewrite the SELECT statement.

This is usefull if you are developping code that needs a set of INSERT, SELECT, UPDATE, and DELETE statements for the same table. This set of functions will parse any of these four SQL statements and rewrite them for you (if they are simple, eg. no joins to other tables). Just mark a SQL statement and call sql-to-insert, sql-to-select, sql-to-update, or sql-to-delete.

Obviously this works best if you start with a SELECT or UPDATE statement, because DELETE statements don't have columns and bindvariables, and INSERT statements don't have where clauses.

A possible way to customize your Emacs would be to use the following (assuming you are using SQL Mode):

(add-hook 'sql-mode-hook
	  (function (lambda ()
		      (local-set-key "\C-cu" 'sql-to-update))))
You can’t perform that action at this time.