【问题标题】:How to write and read binary data with RPostgresql如何使用 RPostgresql 读写二进制数据
【发布时间】:2016-06-23 15:48:54
【问题描述】:

我正在尝试执行代码:

连接到服务器

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/lPPmS8yeP9whttps://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

【问题讨论】:

    标签: r rpostgresql bytea


    【解决方案1】:

    据我所知,postgresqlUnescapeBytea 功能仅在 RpostgreSQL 包的开发版本中可用,可以在这里下载:https://github.com/codeinthehole/rpostgresql

    【讨论】:

    • 包作者指出,开发版本可能无法在所有操作系统/平台上以相同的方式运行,这是阻碍其向 CRAN 发展的原因。我有一个使用 R 3.3.2 和最新版本的 RStudio 的 Windows 7 操作系统,开发版对我来说很好。
    猜你喜欢
    • 2013-12-20
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多