[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Is it possible to pass variable to variables of src block?
From: |
Michael Welle |
Subject: |
Re: [O] Is it possible to pass variable to variables of src block? |
Date: |
Wed, 13 Dec 2017 10:57:28 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.3.50 (gnu/linux) |
Hello,
Xi Shen <address@hidden> writes:
> Hi Michael,
>
> Yes, I think this is a way to my previous question. But what I really want
> to achieve is to loop through a list of server names and execute a script
> on them.
>
> Say I have 20 different database server. How can I do a loop with each
> server?
interestingly I did not found a good solution after a bit of thinking...
The best I could come up with is something like this (which doesn't work):
#+name: foosql
#+BEGIN_SRC sql :dbuser weather :database environment :engine postgresql
select time, temperature from weather limit 10;
#+END_SRC
#+begin_src emacs-lisp :results raw :var hosts=(list "db1" "db2" "db3")
(dolist (host hosts)
(org-sbe foosql (concat ":dbhost " host)))
#+end_src
Error: Symbol's definition is void: host. I guess that's caused by the
way the macro is evaluated. And the result, if any, of the sql query had
to be transformed back into a nice table for some use cases.
Using other means of calling a code block, like #+call etc., aren't
suitable for usage in a loop. So maybe someone can come up with a nice
solution ;).
Regards
hmw