r - SQLDF 在来自 R 的 PostgreSQL 查询上失败
问题描述
PostgreSQL 版本:11
R版本:3.5.2
操作系统:Windows 10
驱动程序:PostgreSQL ANSI(x64)
library(RODBC)
library(sqldf)
conn = odbcConnect("DVDRental") #works
odbcDataSources() #works
sqlTables(conn) #works
customers = sqldf(connection = conn, "select * FROM customer") #fails
错误消息:(函数(类,fdef,mtable)中的错误:无法找到签名“字符”,“字符”的函数“dbGetQuery”的继承方法</p>
有没有更新的方法将 R 连接到 Postgres?谷歌搜索发现了一大堆代码,这些代码似乎都不起作用。
如果你想尝试运行它,你可以下载我在这里使用的示例数据库:http ://www.postgresqltutorial.com/postgresql-sample-database/
我正在使用一个名为 DVDRental 的 DSN。
解决方案
使用RPostgreSQL
库获取连接,使用选项:
library(RPostgreSQL)
options(sqldf.RPostgreSQL.user ="postgres",
sqldf.RPostgreSQL.password ="password",
sqldf.RPostgreSQL.dbname ="test",
sqldf.RPostgreSQL.host ="localhost",
sqldf.RPostgreSQL.port =5432)
customers = sqldf("SELECT * FROM customer")
推荐阅读
- java - Spark广播大列表无法序列化
- c - C - 双指针为 NULL。链表结构
- css - 有没有办法将 CSS 过滤器应用于 IOS 中嵌入的视频?
- javascript - 邮递员获取 Gmail 电子邮件 ID,遍历电子邮件 ID?
- java - Spring @Transactional 卡在 GCP Pub/Sub 异步订阅者内部
- bash - 在 kali linux 终端上,如何在 nano 或 vim 上创建一个 20 字的 .txt 并制作一个脚本 bash,为每个注册表添加一个数字?
- python - pymc3 不使用 OMP_NUM_THREADS 指定的所有内核
- javascript - 如何获取特定时区中特定时间的纪元时间?
- java - Applet 上的键盘输入运动
- reactjs - 使用 Material-ui 创建带有标签、文本、选择和按钮元素的内联表单(类似于 Boostrap)