Yes. ob-sql
is what I would use. Link to documentation with examples: https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-sql.html
You can specify your connection credentials directly as parameters of the source block:
#+begin_src sql :engine postgresql :dbhost HOSTNAME :dbuser USERNAME :dbpassword PASSWORD :database DBNAME
SELECT * FROM TABLE
LIMIT 100
#+end_src
The results are formatted as org-mode table in RESULTS
block below after execution.
You could also configure the credentials under a header with (source):
* some header that the sql source block will be in
:PROPERTIES:
:header-args+: :results table
:header-args+: :engine mssql
:header-args+: :dbhost 123.123.123.123
:header-args+: :database database-name-a
:header-args+: :dbuser username-a
:header-args+: :dbpassword password-a
:END:
ob-sql.el
andob-sqlite.el
. The latter is specific tosqlite
but the former can handle different database engines. Read the beginning ofob-sql.el
to see how to use it and check out also the SQL doc on Worg.