emacs-orgmode
[Top][All Lists]
Advanced

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

[O] adding code before org-babel sql execution (postgres engine)


From: dmg
Subject: [O] adding code before org-babel sql execution (postgres engine)
Date: Tue, 6 Sep 2016 11:13:46 -0700

Hi there

I have been using or-sql with postgres backend for a long time.
There has been one annoyance that I finally fixed.

When the SQL command has an error, it simply outputs
and empty table:

#+begin_src sql :engine postgresql :cmdline  imdb
select * from abc
#+end_src

#+RESULTS:

The error is not detected. I read the documentation of psql and the problem
seems to be that psql does not return an error code by default (even with invalid
commands).

This can be fixed two ways:

1. add to ~/.psqlrc

\set ON_ERROR_STOP on

2. By adding to the command, before it is executed by babel, this line. In
non-interactive mode psql will stop in the first error with an error code
and babel will catch it:

psql:/tmp/babel-51865ab/sql-in-5186Wyu:1: ERROR:  relation "abc" does not exist
LINE 1: select * from abc
                      ^
I am willing to implement #2, but the question is, is there a clean, easy way
to do this? Any hints on how to do it?

thank you very much,

--daniel




--
--dmg

---
Daniel M. German
http://turingmachine.org

reply via email to

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