Hay 2 tipos de manchas en PostgreSQL — BYTEA
y Large Objects
. Recomiendo no usar objetos grandes ya que no puede unirlos a las tablas.
Para BYTEA, usaría algo como esto en libpq:
PGresult* put_data_to_tablename(
PGconn* conn,
int32_t id,
int data_size,
const char* const data
) {
PGresult* result;
const uint32_t id_big_endian = htonl((uint32_t)id);
const char* const paramValues[] = { &id_big_endian, data };
const int nParams = sizeof(paramValues) / sizeof(paramValues[0]);
const int paramLenghts[] = { sizeof(id_big_endian), data_size };
const int paramFormats[] = { 1, 1 }; /* binary */
const int resultFormat = 0; /* text */
result = PQexecParams(
conn,
"insert into tablename (id, data) values ($1::integer, $2::bytea)",
nParams,
NULL, /* Types of parameters, unused as casts will define types */
paramValues,
paramLenghts,
paramFormats,
resultFormat
);
return result;
}