Hi,
I have committed r257 just now, which hopefully give you a minimal support to deal with bytea datatype.
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]])
You will be able to insert and retrieve the binary data. The example shows that
the retrieved raw data ser2 is identical to the initial serialized data ser.
> rows<-dbGetQuery(con, "SELECT * from byteatable")
> ser2<-postgresqlUnescapeBytea(rows[[2]])
> dbGetQuery(con, "drop table byteatable")
NULL
> dbGetQuery(con,"CREATE TABLE byteatable (name text NOT NULL, val bytea, PRIMARY KEY (name))")
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "byteatable_pkey" for table "byteatable"
NULL
> sample.object <- list("one","two");
> ser <- serialize(sample.object,NULL,ascii=F);
> postgresqlEscapeBytea(con, ser)
[1] "X\\\\012\\\\000\\\\000\\\\000\\\\002\\\\000\\\\003\\\\000\\\\000\\\\000\\\\002\\\\003\\\\000\\\\000\\\\000\\\\000\\\\023\\\\000\\\\000\\\\000\\\\002\\\\000\\\\000\\\\000\\\\020\\\\000\\\\000\\\\000\\\\001\\\\000\\\\004\\\\000\\\\011\\\\000\\\\000\\\\000\\\\003one\\\\000\\\\000\\\\000\\\\020\\\\000\\\\000\\\\000\\\\001\\\\000\\\\004\\\\000\\\\011\\\\000\\\\000\\\\000\\\\003two"
> iq <- sprintf("INSERT INTO byteatable values('%s',E'%s');","name1", postgresqlEscapeBytea(con, ser))
> dbGetQuery(con, iq)
NULL
> rows<-dbGetQuery(con, "SELECT * from byteatable")
> ser2<-postgresqlUnescapeBytea(rows[[2]])
> ser2
[1] 58 0a 00 00 00 02 00 03 00 00 00 02 03 00 00 00 00 13 00 00 00 02 00 00 00
[26] 10 00 00 00 01 00 04 00 09 00 00 00 03 6f 6e 65 00 00 00 10 00 00 00 01 00
[51] 04 00 09 00 00 00 03 74 77 6f
> ser
[1] 58 0a 00 00 00 02 00 03 00 00 00 02 03 00 00 00 00 13 00 00 00 02 00 00 00
[26] 10 00 00 00 01 00 04 00 09 00 00 00 03 6f 6e 65 00 00 00 10 00 00 00 01 00
[51] 04 00 09 00 00 00 03 74 77 6f
--
Tomoaki NISHIYAMA
Advanced Science Research Center,
Kanazawa University,
13-1 Takara-machi,
Kanazawa, 920-0934, Japan