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 via email to