From: Stig Brautaset <stig@brautaset.org>
To: emacs-orgmode@gnu.org
Subject: ob-sql: setting :dbhost from a variable
Date: Thu, 07 Jul 2016 00:45:05 +0100 [thread overview]
Message-ID: <m2zipunxfi.fsf@brautaset.org> (raw)
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
reply other threads:[~2016-07-06 23:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2zipunxfi.fsf@brautaset.org \
--to=stig@brautaset.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).