emacs-orgmode
[Top][All Lists]
Advanced

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

[O] Calling org babel to each row in a table


From: Joe Bogner
Subject: [O] Calling org babel to each row in a table
Date: Sun, 30 Jun 2013 11:25:22 -0400

I often need to transform a table or list of values into a block of text. For example, if I have a list of 4 files that I want to generate a SQL script for.

After hunting around, this is the best I came up with:

#+name: table
| File |
| a    |
| b    |
| c    |
| d    |

#+name: template 
#+begin_src org :results verbatim :var name="abc"
DROP TABLE $name

CREATE TABLE $name (name varchar(100))

BULK INSERT $name FROM '\\1.1.1.1\$name.txt' ...
#+end_src

#+name: apply-template 
#+begin_src emacs-lisp :results silent :var table=()
(let (result-table)
    (dolist (line (cdr table))
        (setq result-table (cons (concat "#+call: template(\"" (car line) "\") :results raw drawer") result-table)))
    (mapconcat 'identity (nreverse result-table) "\n"))
#+end_src

#+call: apply-template(table) :results org :exports both

#+RESULTS: apply-template(table):results org :exports both
#+BEGIN_SRC org
#+END_SRC



Is there a more straightforward method to apply this type of transformation? Ideally I would skip the emacs-lisp block and use some syntax to apply a org-babel block for each row in a table.


It sounded similar to this: http://thread.gmane.org/gmane.emacs.orgmode/69326/focus=69340, but that didn't have a full example for me to build off of

Is there a more straightforward to accomplish this transformation?

Thanks,
Joe

reply via email to

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