[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] ob-sql: setting :dbhost from a variable

From: Stig Brautaset
Subject: [O] ob-sql: setting :dbhost from a variable
Date: Thu, 07 Jul 2016 00:45:05 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (darwin)


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;
    #+BEGIN_SRC sql :dbhost db2.example.com
      SELECT 2;
    ... 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;
    #+BEGIN_SRC sql :dbhost $db2
      SELECT 2;
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;
    #+BEGIN_SRC sql :dbhost {{{db2}}}
      SELECT 2;

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?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]