Skip to content

Add rows or update on a blob/varbinary in SQL server gives "[ODBC Driver 17 for SQL Server]String data, right truncation" error #1605

@martedv

Description

@martedv

When updating or adding a row in a database with a "blob/varbinary" column in sql server, an error is thrown.

This fails:

con <- DBI::dbConnect(odbc::odbc(),
    driver = "ODBC Driver 17 for SQL Server",
    server = db.keys[["server"]],
    database = "BlobDB",
    uid = db.keys[["uid"]],
    pwd = db.keys[["pwd"]]
  )
# table with blob_id (int) and blob (varbinary)
x <- con %>% tbl("table_with_blob")

y<- data.frame(blob_id=2, blob = blob::as_blob(base::serialize("test string in blob", NULL)))

rows_update(x, y, by = "blob_id", copy = TRUE, in_place = TRUE, unmatched = "ignore")
# gives: [Microsoft][ODBC Driver 17 for SQL Server]String data, right truncation
# same thing for rows_append

While it works with DBI:

y<- data.frame(blob = blob::as_blob(base::serialize("test string in blob", NULL)))
# this works
DBI::dbAppendTable(con, "table_with_blob", y)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions