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

Parameterized queries not working with "?" #201

Open
ChuliangXiao opened this issue Nov 14, 2018 · 3 comments

Comments

@ChuliangXiao
Copy link

commented Nov 14, 2018

Parameterized queries at db.rstudio.com
The following query works when using DBI::dbConnect(odbc::odbc()),

airport <- dbSendQuery(con, "SELECT * FROM airports WHERE faa = ?")

, but not DBI::dbConnect(RPostgres::RPostgres()).

@krlmlr

This comment has been minimized.

Copy link
Member

commented Nov 26, 2018

Thanks. For RPostgres you need placeholders like $1, $2 etc.. Until we have consistent placeholders across backends (r-dbi/DBI#52), it would be great to document this somewhere.

@edgararuiz: Is db.rstudio.com a good place to document this?

@krlmlr krlmlr added the docs label Nov 26, 2018

@ChuliangXiao

This comment has been minimized.

Copy link
Author

commented Nov 26, 2018

@krlmlr Thank you very much.
Just tested. For DBI::dbConnect(RPostgres::RPostgres()) connection con, it works as following.

airport <- dbSendQuery(con, "SELECT * FROM airports WHERE faa = $1 or faa = $2")
dbBind(airport, list("GPT", "MSY"))
dbFetch(airport)
@edgararuiz

This comment has been minimized.

Copy link

commented Jan 10, 2019

Just opened an Issue for the db.rstudio.com site. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.