0

I have quite a few SQL org-babel functions for fetching various(single record) IDs from the database.

The snippet below works, but is there any way to skip that middle function that converts SQL result to a simple string? My goal here is to DRY this org-mode/org-babel file.

#+name: raw-sql-token
#+BEGIN_SRC sql :results value
  SELECT 123 AS token
#+END_SRC

#+name: sql-token
#+BEGIN_SRC sql :var input=raw-sql-token :results value
  (print (nth 0(nth 0 input)))
#+END_SRC

#+HEADER: :var id=sql-token
#+BEGIN_SRC http :pretty
  GET http://localhost:3000/api/items/${id}
#+END_SRC
1

You can use indexing on the result table to select the cell you want:

#+HEADER: :var id=raw-sql-token[2,0]
#+BEGIN_SRC http :pretty
  GET http://localhost:3000/api/items/${id}
#+END_SRC
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.