* ob-sql: setting :dbhost from a variable
@ 2016-07-06 23:45 Stig Brautaset
0 siblings, 0 replies; only message in thread
From: Stig Brautaset @ 2016-07-06 23:45 UTC (permalink / raw)
To: emacs-orgmode
Hello!
I have an Org document that does several SQL queries against two different
PostgreSQL databases. Currently I set the =:dbhost= header argument for each
source block, like this:
#+BEGIN_SRC sql :dbhost db1.example.com
SELECT 1;
#+END_SRC
#+header:
#+BEGIN_SRC sql :dbhost db2.example.com
SELECT 2;
#+END_SRC
... many other queries against both dbs omitted ...
Having the hosts all over my org document is a bit annoying. I would like to
specify them in a property section at header/buffer level, but haven't figured
out how to do this. I would *love* to be able to do something like this:
#+property: header-args :var db1="db1.example.com" db2="db2.example.com"
#+BEGIN_SRC sql :dbhost $db1
SELECT 1;
#+END_SRC
#+BEGIN_SRC sql :dbhost $db2
SELECT 2;
#+END_SRC
However, that does not appear to work. I also tried using macros, but this did
not work either:
#+macro: db1 db1.example.com
#+macro: db2 db2.example.com
#+BEGIN_SRC sql :dbhost {{{db1}}}
SELECT 1;
#+END_SRC
#+BEGIN_SRC sql :dbhost {{{db2}}}
SELECT 2;
#+END_SRC
I got this error:
: psql: could not translate host name "{{{db1}}}" to address: Name or service not known
Finally I tried to do this by using :session, setting the :dbhost only
on the first instance, but did not work either.
Does anyone have any tips for how I can consolidate all my explicit (and
duplicated) :dbhost stanzas?
Stig
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2016-07-06 23:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-06 23:45 ob-sql: setting :dbhost from a variable Stig Brautaset
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).