Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] Run SQL chunk with DBI option immediate = TRUE ? #2241

Open
JrmFRL opened this issue Oct 27, 2021 · 5 comments · May be fixed by yihui/knitr#2128
Open

[FR] Run SQL chunk with DBI option immediate = TRUE ? #2241

JrmFRL opened this issue Oct 27, 2021 · 5 comments · May be fixed by yihui/knitr#2128
Labels
feature a feature request or enhancement help wanted ❤️ we'd love your help! theme: knitr concerns knitr package

Comments

@JrmFRL
Copy link

JrmFRL commented Oct 27, 2021

I understand from the documentation that DBI is used in backend to run SQL chunk.

I try to reproduce the behaviour of running of R instruction similar to:

DBI::dbGetQuery(con, statement = "SELECT * FROM mytable LIMIT 10", immediate = TRUE)

but I could not find any option to pass in the sql chunk header, such as:

```{sql, output.var = "data", connection = "con", immediate = TRUE}
SELECT * FROM mytable LIMIT 10
```

I tried many things such as:

  • immediate = "TRUE/True"
  • params = parameters with parameters <- list(immediate = TRUE) ...

but could not success.

Is there a way to achieve this I have not thought about ?
Thank you !

@AWKruijt
Copy link

Found this while looking for that exact same desired functionality - an ' immediate = T' chunk option would be amazing.

@cderv cderv added the feature a feature request or enhancement label Nov 2, 2021
@cderv
Copy link
Collaborator

cderv commented Nov 2, 2021

@JrmFRL this is not supported to passe any option to dbGetQuery. Support should be added.

Just some notes if someone wants to tackle this, if possible, by a PR:

Anyone willing to help with this is welcomed! Thanks !

@cderv cderv added the help wanted ❤️ we'd love your help! label Nov 2, 2021
@cderv cderv moved this to Backlog in R Markdown Team Projects Dec 22, 2021
@cderv cderv added next to consider for next release theme: knitr concerns knitr package and removed next to consider for next release labels Dec 22, 2021
@AWKruijt
Copy link

AWKruijt commented May 17, 2022

So...I'm really craving this immediate option for SQL chunks and tried to have a go at this myself yet I seem to lack the insight on how to get Rstudio to actually use a modified engine.

The edited engine.R file can be found here in this forked repos: https://github.com/AWKruijt/knitr_add_sql_immediate. Not sure if this is actually all that is required to get it to work (I am probably being wonderfully naive now) but I think it shouldn't require much more than this either?

Yet, as said, I seem unable to get the thing to test run >.< If someone could give it a spin that would be awesome.

@AWKruijt
Copy link

Big update I think :) Using a knitr::knit_engines$set()-style test I think I managed to iron most details out now. See latest commit at this forked repos: https://github.com/AWKruijt/knitr_add_sql_immediate. In addition to the option immedate, I've also added and option replace which (if TRUE) adds code to remove an existing temporary table before executing an "into" query. My attempt at custom error handling in case of attempt to replace a non-temporary table doesn't yet work however.

Not sure what the next step is now? Should I initiate a PR?

@cderv
Copy link
Collaborator

cderv commented May 18, 2022

Hi @AWKruijt,

Thanks for your work on this feature! This sounds great!

Not sure what the next step is now? Should I initiate a PR?

Yes please open a PR, it will be easier for us to review and test ! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement help wanted ❤️ we'd love your help! theme: knitr concerns knitr package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants