Database Reference
In-Depth Information
You will observe different OIDs when practicing these examples.
It's quite evident now that you have successfully imported an image inside a
database and it has been assigned an OID as well.
You learned how to import an object; exporting or retrieving a large object can be
simpler as well but with the difference that you will use the
lo_export()
function
along with the OID in the following manner:
postgres=# SELECT lo_export(74441, '/tmp/pg_disney_second.jpg');
lo_export
-----------
1
(1 row)
If you visit the
/tmp
directory, you will ind an image
with the name
pg_disney_second.jpg
.
This is how you retrieve large objects from the database, and in the end, we will try
to delete this large object using the
lo_unlink()
function in the following manner:
postgres=# SELECT lo_unlink(74441);
lo_unlink
-----------
1
(1 row)
You might observe the usage of OID as a reference to export and unlink the
large objects. To make sure that it goes well, let's query the
pg_largeobject
and
pg_largeobject_metadata
tables again.
First, query the
pg_largeobject
table using the following statement:
postgres=# SELECT loid FROM pg_largeobject;
loid
--------
(0 rows)
Then, query the
pg_largeobject_metadata
table using the following statement:
postgres=# SELECT oid FROM pg_largeobject_metadata;
oid
--------
(0 rows)