From mboxrd@z Thu Jan 1 00:00:00 1970 From: dmg Subject: babel and postgresql Date: Sat, 23 Feb 2013 22:42:31 -0800 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:35013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9VIu-0002WV-Fa for emacs-orgmode@gnu.org; Sun, 24 Feb 2013 01:43:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U9VIn-0003q2-4x for emacs-orgmode@gnu.org; Sun, 24 Feb 2013 01:43:20 -0500 Received: from mail-wi0-f173.google.com ([209.85.212.173]:54445) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U9VIm-0003pn-Rf for emacs-orgmode@gnu.org; Sun, 24 Feb 2013 01:43:12 -0500 Received: by mail-wi0-f173.google.com with SMTP id hq4so2292257wib.6 for ; Sat, 23 Feb 2013 22:43:11 -0800 (PST) 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode Cc: eschulte@cs.unm.edu Hi everybody, Eric, I have been starting using Babel with postgresql, R and perl, and I am loving it. I really want to thank everybody for their work. I have found one particular issue that bothers me. Say I have the following babel section: #+name: abc #+begin_src sql :engine postgresql :cmdline mydb select * from aliases limit 1; #+end_src the output is: #+name: abc | alias | uniname | | Jon | jon | Note how the column names are not separated from the body: What I want it this: #+name: | alias | uniname | |---------------------------+--------------| | Jon | jon | I have tracked the problem, and it is that in ob-sql.el the code of org-babel-execute:sql thinks that postgres will return a header separator, and it does not. I am not sure what is the best way to fix it, but I have come with a patch that does it (but replaced the older code). The code in org-babel-execute:sql needs to be modified so it does this only for the postgres backend: split the list into first member and rest and insert a 'hline in between. My solution is rough, but it works (sorry, I am just an elisp beginner) diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el index 3586ec9..95cac85 100644 --- a/lisp/ob-sql.el +++ b/lisp/ob-sql.el @@ -170,11 +170,12 @@ This function is called by `org-babel-execute-src-block'." ) (org-table-import out-file '(16)) (org-babel-reassemble-table - (mapcar (lambda (x) - (if (string= (car x) header-delim) - 'hline - x)) - (org-table-to-lisp)) + (funcall (lambda (x) + (cons (car-safe x) + (cons 'hline (cdr-safe x)) + ) + ) + (org-table-to-lisp)) (org-babel-pick-name (cdr (assoc :colname-names params)) (cdr (assoc :colnames params))) (org-babel-pick-name (cdr (assoc :rowname-names params)) -- --dmg --- Daniel M. German http://turingmachine.org