Blog

2026-04-20 How to quickly generate the list of all columns in a PostgreSQL table

It is well-known that select * is an antipattern (except maybe in an SQL REPL). What to do, however, if you have a select * in your codebase and you want to change it to a proper list of column names? Typing them out manually is fine if there are three of them, but what if there are three dozen? Of course, you may ask an LLM for a nice, comma-separated list of all the columns – but I will generate it three times while you are waiting for the LLM’s answer;-)! (Or, your company – or you personally – might have an anti-LLM policy because of privacy concerns.) Here’s how (of course, in psql). First you turn off the “aligned mode” (I assume you have it enabled, which is a sane default) with \a. Then you say \pset fieldsep ',' to use comma instead of the pipe as column separator. And then, just say select * from my_table limit 0 to only show the header. Optionally, say \a again and restore the column separator with \pset fieldsep '|' – but it’s faster to do all this in a separate, temporary psql session and just exit it.

That’s it for today, see you next week!

CategoryEnglish, CategoryBlog, CategoryPostgreSQL

Comments on this page

2026-04-13 Binding TAB in Dired to something useful

I’m old enough to remember Norton Commander for DOS. Despite that, I never used Midnight Commander nor Sunrise CommanderDired is still my go-to file manager these days. In fact, Dired has a feature which seems to be inspired by NC: when there are two Dired windows, the default destination for copying, moving and symlinking is “the other” window.

Surprisingly, another feature which would be natural in an orthodox file manager is absent from Dired: TAB is not bound by its keymap. This means that pressing it results in a “Buffer is read-only” error. I figured that making TAB switch to the other Dired window would be pretty cool – and definitely more useful than just erroring out.

(defun dired-cycle-dired-windows ()
  "Switch to the next Dired window in the selected frame."
  (interactive)
  (select-window
   (cadr (seq-filter
          (lambda (window)
            (eq (buffer-local-value
                 'major-mode (window-buffer window))
                'dired-mode))
          (window-list)))))

(keymap-set dired-mode-map "TAB" #'dired-cycle-dired-windows)

And that’s it! From now on, pressing TAB in a Dired buffer will cycle through all Dired buffer in the currently selected frame.

Now this command could be made more elaborate. For example, it could go in another direction with a prefix argument. (No point for me, though – very rarely do I have more than two Dired windows open at the same time.) It could cycle through all Emacs frames (doable, but much more work for little gain). It could switch to another Dired buffer in the same window if there’s only one (clever, but I’m not sure if useful). That’s not the point – the point I’m making over and over again is that creating little but useful commands like this is a breeze in Emacs. In fact, creating this one took me maybe 10 minutes – and it would be under 5 minutes if not for the fact that I had to look up a few things, like how to get the buffer given the window, how to get major mode given a buffer etc.

As usual, I recommend the late Robert J. Chassell’s Introduction to Programming in Emacs Lisp if you want to learn to write commands like this and mold Emacs to your needs – and my book about Emacs Lisp if you want to see a few more (and more advanced) examples.

That’s it for today, until next time!

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryDired

Comments on this page

2026-04-05 Easter 2026

Christ has risen, rejoice! I have a bit of a rough time right now, but we have Good News – Jesus is greater than our troubles!

Like in previous years, rest assured that I will pray a decade of the Rosary for all of you, my dear readers.

Hallelujah!

CategoryEnglish, CategoryBlog, CategoryFaith

Comments on this page

More...

CategoryBlog