Sequel Pro query favorites with tab snippets

If you use the fantastic Sequel Pro for all your MySQL needs on the Mac, here's a tip for you.

Custom query tab snippets is a feature that was added in Sequel Pro 0.9.8. Here's the documentation (which is quite well done, I must say).

The tab snippets feature allows you to add insertion points to your query favorite. This works similarly to TextMate, where you can tab through HTML attributes after inserting a tag with the HTML bundle.

Let's set up a quick example. We're going to set up a favorite that will allow us to quickly re-sort (ALTER TABLE ... ORDER BY ...) any table by any field.

Most of the time you're probably going to want to re-sort the currently selected table by its id field, so we'll make that the default.


I won't go into specifics on syntax, or how this works, since the documentation explains things pretty well. You can also use the Insert Placeholder dropdown to help you build your own custom queries.

Add the query above to your query favorites, give it a nice name, and assign it a tab trigger. I used order.

Tab trigger

Now, when you're in Sequel Pro's query editor, just type order, press Tab, and you should see something like this (I have the photos table selected in this case):

Snippet example

You can now type over the table name, and both instances will be changed. Press Tab again if you need to change the field to order by. For bonus points, you can even use autocompletion to fill out your table name and field name. At any time, press ⌘-R or Enter to run the query.

I don't know about you, but this satisfies my keyboardophilia quite a bit. Hopefully this gets you thinking about how you can use Sequel Pro's custom query tab snippets to your advantage.