emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: dmg <dmg@turingmachine.org>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: adding code before org-babel sql execution (postgres engine)
Date: Tue, 6 Sep 2016 11:13:46 -0700	[thread overview]
Message-ID: <CAEBXXD-fJWrMzfBX-Y7gD9fj76tgnu6EVKfAz5RREyXHStsSaA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1046 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 3889 bytes --]

                 reply	other threads:[~2016-09-06 18:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEBXXD-fJWrMzfBX-Y7gD9fj76tgnu6EVKfAz5RREyXHStsSaA@mail.gmail.com \
    --to=dmg@turingmachine.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).