Proper way to pass parameters to query in R DBI

后端 未结 2 423
闹比i
闹比i 2020-12-16 21:41

In perl/python DBI APIs have a mechanism to safely interpolate in parameters to an sql query. For example in python I would do:

cursor.execute(\"SELECT * FR         


        
2条回答
  •  不知归路
    2020-12-16 22:26

    Indeed the use of bind variables is not really well documented. Anyway the ODBC commands in R work differently for different databases. One possibility for postgres would be like this:

    res <- postgresqlExecStatement(con, "SELECT * FROM table WHERE value > $1", c(5))
    postgresqlFetch(res)
    postgresqlCloseResult(res)
    

    Hope it helps.

提交回复
热议问题