postgresExportLargeObject: Exports a large object to file

View source: R/PqConnection.R

postgresExportLargeObjectR Documentation

Exports a large object to file

Description

Exports a large object from the database to a file on disk. This function uses PostgreSQL's lo_export() function which efficiently streams the data directly to disk without loading it into memory, making it suitable for very large objects (GB+) that would cause memory issues with lo_get(). This function must be called within a transaction.

Usage

postgresExportLargeObject(conn, oid, filepath)

Arguments

conn

a PqConnection object, produced by DBI::dbConnect()

oid

the object identifier (Oid) of the large object to export

filepath

a path where the large object should be exported

Value

invisible NULL on success, or stops with an error

Examples

## Not run: 
con <- postgresDefault()
filepath <- 'your_image.png'
dbWithTransaction(con, {
  oid <- postgresImportLargeObject(con, filepath)
})
# Later, export the large object back to a file
dbWithTransaction(con, {
  postgresExportLargeObject(con, oid, 'exported_image.png')
})

## End(Not run)

RPostgres documentation built on Feb. 6, 2026, 9:07 a.m.