emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* babel and postgresql
@ 2013-02-24  6:42 dmg
  2013-02-24  7:13 ` dmg
  0 siblings, 1 reply; 3+ messages in thread
From: dmg @ 2013-02-24  6:42 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: eschulte

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 <tixy@xyz.org>        | jon          |

Note how the column names are not separated from the body:

What I want it this:

#+name:
| alias                     | uniname      |
|---------------------------+--------------|
| Jon <tixy@xyz.org>        | 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: babel and postgresql
  2013-02-24  6:42 babel and postgresql dmg
@ 2013-02-24  7:13 ` dmg
  2013-02-24  8:15   ` Bastien
  0 siblings, 1 reply; 3+ messages in thread
From: dmg @ 2013-02-24  7:13 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: eschulte

It looks like my inexperience with Lisp made me ignore the obvious.
What is needed is not my patch below, but to add posgresql to the
condition of the case:

From:
	(case (intern engine)
	  ('mysql


To:

	(case (intern engine)
	  ('(postgresql mysql)

the problem is that I can't get it to work (and I could not find good
documentation for the case macro anywhere but its definition. It says
that it takes either an atom (i.e. 'mysql)
or a list (i.e. '(postgresql mysql) ) but it just does not work me.

But the code for mysql and postgres seems to be the same.

Sorry for the confusion.

--daniel

On Sat, Feb 23, 2013 at 10:42 PM, dmg <dmg@uvic.ca> wrote:
> 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 <tixy@xyz.org>        | jon          |
>
> Note how the column names are not separated from the body:
>
> What I want it this:
>
> #+name:
> | alias                     | uniname      |
> |---------------------------+--------------|
> | Jon <tixy@xyz.org>        | 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



-- 
--dmg

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: babel and postgresql
  2013-02-24  7:13 ` dmg
@ 2013-02-24  8:15   ` Bastien
  0 siblings, 0 replies; 3+ messages in thread
From: Bastien @ 2013-02-24  8:15 UTC (permalink / raw)
  To: dmg; +Cc: emacs-orgmode, eschulte

Hi Daniel,

dmg <dmg@uvic.ca> writes:

> It looks like my inexperience with Lisp made me ignore the obvious.
> What is needed is not my patch below, but to add posgresql to the
> condition of the case:
>
> From:
> 	(case (intern engine)
> 	  ('mysql
>
>
> To:
>
> 	(case (intern engine)
> 	  ('(postgresql mysql)
>
> the problem is that I can't get it to work (and I could not find good
> documentation for the case macro anywhere but its definition. It says
> that it takes either an atom (i.e. 'mysql)
> or a list (i.e. '(postgresql mysql) ) but it just does not work me.

I applied this patch, which should do the right thing given your
explanations:

  http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=f8e874

Let me know.  Thanks!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-02-24  8:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-24  6:42 babel and postgresql dmg
2013-02-24  7:13 ` dmg
2013-02-24  8:15   ` Bastien

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