本文介绍了如何使用RPostgresql写入和读取二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试执行代码:
连接到服务器
library('RPostgreSQL', quietly = TRUE)
kHostName <- '...'
kPort <- '5432'
kDBName <- '...'
kUser <- '...'
kPassword <- '...'
drv <- dbDriver("PostgreSQL")
con <- dbConnect(drv,
host = kHostName,
port = kPort,
dbname = kDBName,
user = kUser,
password = kPassword)
以下部分代码摘自 https://groups .google.com/forum/#!topic/rpostgresql-dev/lPPmS8yeP9w 和 https://github.com/codeinthehole/rpostgresql/blob/master/RPostgreSQL/tests/bytea.R
dbGetQuery(con,"CREATE TABLE byteatable (name text NOT NULL, val bytea,
PRIMARY KEY (name))")
sample.object <- list("one","two");
ser <- serialize(sample.object,NULL,ascii=F);
postgresqlEscapeBytea(con, ser)
iq <- sprintf("INSERT INTO byteatable values('%s',E'%s');","name1", postgresqlEscapeBytea(con, ser))
dbGetQuery(con, iq)
rows<-dbGetQuery(con, "SELECT * from byteatable")
ser2<-postgresqlUnescapeBytea(rows[[2]])
它返回:
Error: could not find function "postgresqlEscapeBytea"
我如何使它工作?
我使用:
> version
_
platform x86_64-apple-darwin13.4.0
arch x86_64
os darwin13.4.0
system x86_64, darwin13.4.0
status
major 3
minor 3.0
year 2016
month 05
day 03
svn rev 70573
language R
version.string R version 3.3.0 (2016-05-03)
nickname Supposedly Educational
推荐答案
据我所知,函数postgresqlUnescapeBytea
仅在RpostgreSQL
包的开发版本中可用,可以在此处下载: https://github.com/codeinthehole/rpostgresql
The function postgresqlUnescapeBytea
is only available in the development version of the RpostgreSQL
package as far as I'm aware, which can be downloaded here: https://github.com/codeinthehole/rpostgresql
这篇关于如何使用RPostgresql写入和读取二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!