-
Notifications
You must be signed in to change notification settings - Fork 79
Send raw SQL to database backend #213
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
Comments
Thanks. Unfortunately this is a limitation of many database backends, and DBI supports only the lowest common denominator -- submitting individual queries. Perhaps squr or other related projects can help? |
Thanks. I actually checked
Once you have that function, you can use it to submit I believe that still gets me back to the first problem: having a function to send raw SQL to the database backend in the first place. You also pointed out dbr in the same issue thread, however, AFAICT that's built on top of DBI. |
Thanks for the heads up. There are other situations where using a "regular", non-prepared query is useful, e.g. RMariaDB doesn't support certain query types with its "prepared" API (r-dbi/DBI#268). We might be able to support execution of multiple queries if we support the non-prepared API here too. For now, seems like your best bet is to look for semicolons at EOL, e.g. with:
and sending these one by one with |
Thanks! Yes, I'd love to see the non-prepared API; until then, that's a good workaround. |
Thank you both for the valuable information provided here. I was wondering if there is a better way to parse the SQL statements apart from splitting by the semicolon. Is there an R package you would advise for this? I recently stumbled upon problems with some more advanced SQL, where parsing on the semi column did not do the trick. I attached an example with solution below in case anyone is having similar problems. Support for the non-prepared API would of course still be the better solution I believe. example SQL code with semi columns:
solution = introduce the semi columns again for code defined between two "$BODY$"'s:
|
I'm not sure it's possible to reliably split SQL -- it's something that the database backend needs to do. According to the docs, if we use |
Thank you for your feedback, I agree. |
Now in #272. |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary. |
Background: I'm trying to initialize a database. I have a
ddl
file that contains a set of SQL statements, e.g.I'd like to read the file and send the query as-is to the PostgreSQL backend, e.g.
Alas, I receive an error --
I also tried the other send approach (
dbExecute
,dbSendQuery
, etc) available in theRPostgres
package, and could not locate any other method that would let me do that.I don't have the skills to navigate the
C++
code; my crude read is that this error seems to arise when invoking the underlying Postgres functionPQPrepare
. It appears that a limitation of PostgreSQL is that there can only be one command per prepared statement (reference).Desired Solution: Provide a mechanism to send raw SQL to the backend system without the SQL being be a prepared query.
I'm aware that an alternative is to write the table construction logic in R; I'd prefer to avoid that for interoperability reasons (i.e. I can paste into a SQL prompt; I can invoke via Python, etc) as well as clarity (I work with more people than can read SQL than can read R).
The text was updated successfully, but these errors were encountered: