emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* adding code before org-babel sql execution (postgres engine)
@ 2016-09-06 18:13 dmg
  0 siblings, 0 replies; only message in thread
From: dmg @ 2016-09-06 18:13 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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 --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-09-06 18:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-06 18:13 adding code before org-babel sql execution (postgres engine) dmg

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).