From mboxrd@z Thu Jan 1 00:00:00 1970 From: dmg Subject: adding code before org-babel sql execution (postgres engine) Date: Tue, 6 Sep 2016 11:13:46 -0700 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=94eb2c04c702671eae053bdac472 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhKtC-0007wD-5X for emacs-orgmode@gnu.org; Tue, 06 Sep 2016 14:14:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhKtA-0002EB-Rl for emacs-orgmode@gnu.org; Tue, 06 Sep 2016 14:14:29 -0400 Received: from mail-ua0-x22a.google.com ([2607:f8b0:400c:c08::22a]:35674) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhKtA-0002E5-MV for emacs-orgmode@gnu.org; Tue, 06 Sep 2016 14:14:28 -0400 Received: by mail-ua0-x22a.google.com with SMTP id 71so13728246uag.2 for ; Tue, 06 Sep 2016 11:14:28 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode --94eb2c04c702671eae053bdac472 Content-Type: text/plain; charset=UTF-8 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 --94eb2c04c702671eae053bdac472 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi there

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

When the S= QL command has an error, it simply outputs
and empt= y table:

#+beg= in_src sql :engine postgresql :cmdline =C2=A0imdb
select * from a= bc
#+end_src

#+RESULTS:

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

This can be fixed two ways:

1. add to ~/.psqlrc
<= br>
\set ON_ERROR_STOP on

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

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

t= hank you very much,

--daniel

=


--
-= -dmg

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