Comments on 2020-03-09 Using Org-mode as a PostgreSQL client

Last edit

Summary: Hi, thanks for all the comments! I'm very busy now, but I will address them in another post in a week or two -- stay tuned!

Added:

> ----
> Hi, thanks for all the comments! I'm very busy now, but I will address them in another post in a week or two -- stay tuned!
> -- Marcin Borkowski 2020-03-23 22:14 UTC


Cool article! I’ve started using a similar setup recently. You can get away with a single header argument :dbconnection if you add all your settings to the sql-connection-alist. Like so:

(push (“someconnection”
(sql-product ‘postgres)
(sql-user “dbuser”)
(sql-password “password”)
(sql-server “hostaddress”)
(sql-database “database”))
sql-connection-alist)

The benefit is that you can also use it now with M-x sql-connect. Very useful imho. For some reason I had to patch the postgresql emacs integration (using 27.1), maybe this is useful to you too.

(define-advice sql-comint-postgres (:around (fun product options &optional buf-name) sfx-comint-postgres)
(when sql-password
(setenv “PGPASSWORD” sql-password))
(unwind-protect
(funcall fun product options buf-name)
(when sql-password
(setenv “PGPASSWORD”))))

simonfxr 2020-03-11 00:08 UTC


> The canonical Emacs way is the Comint mode

The canonical Emacs way to do what you’re describing for SQL certainly involves the comint-based `sql-interactive-mode`; but you write the queries in a linked `sql-mode` buffer, and then just send them to the SQLi buffer for evaluation.

I can’t tell whether that’s exactly what you were meaning, or if you’ve never noticed that `sql-mode` and `sql-interactive-mode` buffers can interact.

– Anonymous 2020-03-11 02:39 UTC


I was mostly just commenting about heaving to put less information in the org source block headers. I know about linking sqli/sql buffers, but I still prefer working mostly with org source blocks.

simonfxr 2020-03-11 22:37 UTC


Hi simonfxr,

For clarification, my comment was to Marcin in response to the original article, rather than in response to your own comment.

I can also see the appeal of an org-based approach. (I don’t think I’m likely to switch to it myself, but I should probably at least try it.)

– Anonymous 2020-03-14 08:13 UTC


hi marcin. any substitute to \d (to describe table) or \l (to list databases) or \d+ (to describe views) and so on ?
without those, you are stuck with no idea of the objects you have to deal with. thanks

parisni 2020-03-23 07:31 UTC


Hi, thanks for all the comments! I’m very busy now, but I will address them in another post in a week or two – stay tuned!

– Marcin Borkowski 2020-03-23 22:14 UTC