postgresql_16:5.2.3.2 Importing a Large Object
PostgreSQL 16 > Client Interfaces > Large Objects > Client Interfaces > Importing a Large Object
To import an operating system file as a large object, call Oid lo_import(PGconn *conn, const char *filename); *filename* specifies the operating system name of the file to be imported as a large object. The return value is the OID that was assigned to the new large object, or InvalidOid (zero) on failure. Note that the file is read by the client interface library, not by the server; so it must exist in the client file system and be readable by the client application.
The function Oid lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId); also imports a new large object. The OID to be assigned can be specified by *lobjId*; if so, failure occurs if that OID is already in use for some large object. If *lobjId* is InvalidOid (zero) then lo_import_with_oid assigns an unused OID (this is the same behavior as lo_import). The return value is the OID that was assigned to the new large object, or InvalidOid (zero) on failure.
lo_import_with_oid is new as of PostgreSQL 8.4 and uses lo_create internally which is new in 8.1; if this function is run against 8.0 or before, it will fail and return InvalidOid.