1

Is the way to get same output as in terminal with ob-doc-sql.

Executing the sql-query in org will process results into org-table ignoring other than table information. It doesn't fare well with multiple query in the block as show below will squash both into single table.

#+BEGIN_SRC sql :engine postgresql :database postgres
  SELECT 'hello';
  SELECT 'hello', 'world';
#+END_SRC

#+RESULTS:
| ?column? |          |
|----------+----------|
| hello    |          |
| ?column? | ?column? |
| hello    | world    |

header argument :results with output or verbatim value produce correct structure but table formatting is stripped out. But stil doesn't produce any terminal like output as shown below.

#+RESULTS:
: ?column?
: hello world
: ?column?  ?column?
: hello  world

Althouh expected output can be produced via shell execution,

#+BEGIN_SRC sh :results output
  psql postgres -X -c "SELECT 'hello'" -c "SELECT 'hello', 'world';"
#+END_SRC

#+RESULTS:
#+begin_example
 ?column? 
----------
 hello
(1 row)

 ?column? | ?column? 
----------+----------
 hello    | world
(1 row)

#+end_example

  • Nice question! Does ob-doc-sql provide a :session header? Sometimes adding session will alter the results. Also did you try adding :results verbatim to the block? – Melioratus Apr 6 at 14:57
  • according to orgmode.org/worg/org-contrib/babel/languages/ob-doc-sql.html there is no session support. adding verbatim has similar result as output – rho Apr 6 at 15:35

Your Answer

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

Browse other questions tagged or ask your own question.