lo_from_bytea()

A function for creating and populating a large object

lo_from_bytea() is a system function for creating a large object and populating it with data.

lo_from_bytea() was added in PostgreSQL 9.4.

Usage

lo_from_bytea ( loid oid, data bytea ) → oid

If loid is 0 then an OID will be automatically allocated, otherwise the provided OID will be used.

On success, the OID of the created large object is returned, otherwise an error is raised.

Change history

Examples

Basic usage example for lo_from_bytea():

postgres=# SELECT lo_from_bytea(0, '\x48656c6c6f20776f726c64210a');
 lo_from_bytea 
---------------
         16388
(1 row)

postgres=# SELECT * FROM pg_largeobject;
 loid  | pageno |             data             
-------+--------+------------------------------
 16388 |      0 | \x48656c6c6f20776f726c64210a
(1 row)

Attemting to create a large object using an existing OID:

postgres=# SELECT lo_from_bytea(16388, '\xdeadbeef');
ERROR:  duplicate key value violates unique constraint "pg_largeobject_metadata_oid_index"
DETAIL:  Key (oid)=(16388) already exists.

Categories

Large object, System function

See also

lo_put(), lo_get()