ob-sql-mode icon indicating copy to clipboard operation
ob-sql-mode copied to clipboard

Enhancement Request: Argument Passing

Open ghost opened this issue 3 years ago • 4 comments

As compared to the back-end ob-sql, I miss the ability to pass argument values to source blocks.

For instance, this does not work:

#+begin_src sql-mode :var myarg=7.8
  SELECT $myarg + 11 AS sum;
#+end_src

I have only tried PostgreSQL this far, but judging from the error messages, it is the argument passing which fails.

ghost avatar Oct 19 '22 08:10 ghost

I second this. There is a comment on the code saying the author doesn't have a use for it, but I use it extensively to reuse query results. I could be doing that some other way, but I think it is reasonable for a Org Babel back-end to support this. I could probably take a stab at it, but I won't have time available for the foreseeable months...

bigodel avatar Dec 06 '23 01:12 bigodel

I would also like to add that it wouldn't be much trouble to support passing user, password, database and such as header arguments, while still letting sql.el handle it (referencing this other comment) just like its being done with sql-product, we'd just have to get these arguments and bind the appropriate variables (i.e. sql-user, sql-password, sql-database, ...)

bigodel avatar Dec 06 '23 01:12 bigodel

The two cases suggested in this issue — variables (:var) and arguments — e.g. header-arguments for connection — are covered by ob-sql-session. Regarding the last comment, please note that while org variables are, for some programming languages, a simple matter of substitution/evaluation, and as such a piece of cake, arguments, on the other hand, requires careful handling.

flintforge avatar Jun 24 '24 09:06 flintforge

Yeah, at the time of writing this comment ob-sql-session wasn't a thing but I agree it covers the cases mentioned

bigodel avatar Jul 02 '24 14:07 bigodel