nikclayton / ob-sql-mode

sql-mode backend for Org Babel
GNU General Public License v3.0
31 stars 10 forks source link

Enhancement Request: Argument Passing #13

Open desinent opened 1 year ago

desinent commented 1 year ago

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.

bigodel commented 7 months ago

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 commented 7 months ago

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

flintforge commented 1 week ago

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.

bigodel commented 3 days ago

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