From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stig Brautaset Subject: ob-sql: setting :dbhost from a variable Date: Thu, 07 Jul 2016 00:45:05 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKwVn-0005c6-4v for emacs-orgmode@gnu.org; Wed, 06 Jul 2016 19:45:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKwVj-0001BI-0V for emacs-orgmode@gnu.org; Wed, 06 Jul 2016 19:45:46 -0400 Received: from plane.gmane.org ([80.91.229.3]:46675) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKwVi-0001BA-Pj for emacs-orgmode@gnu.org; Wed, 06 Jul 2016 19:45:42 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1bKwVc-0005CL-13 for emacs-orgmode@gnu.org; Thu, 07 Jul 2016 01:45:36 +0200 Received: from host86-154-108-201.range86-154.btcentralplus.com ([86.154.108.201]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 07 Jul 2016 01:45:36 +0200 Received: from stig by host86-154-108-201.range86-154.btcentralplus.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 07 Jul 2016 01:45:36 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org 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