Is it possible to copy a large Postgresql object to a db server?

I have data in a large object, now I want to make a copy of it so that I can add it while keeping a copy of the original. Is there any JDBC call or SQL statement that I can use to make this happen?

From each resource found, it seems to me that I should read all the data to my client and write it again to get a copy. I would rather keep the round trip.

+4
source share
2 answers

A large object can be copied / cloned by two requests if you know its oid .

 INSERT INTO pg_largeobject_metadata (lomowner, lomacl) SELECT lomowner, lomacl FROM pg_largeobject_metadata WHERE oid = <my_old_oid> RETURNING oid AS my_new_oid; INSERT INTO pg_largeobject (loid, pageno, data) SELECT <my_new_oid>, pageno, data FROM pg_largeobject WHERE loid = <my_old_oid>; 

my_old_oid is a large object known as oid
my_new_oid is the oid returned by the first insertion product

pg_large_object reference
Reference to object type identifier (oid)

+3
source

Look at the server-side functions lo_import and lo_export . You will have to move the data from the database to the file system and vice versa, but at least it is the server file system, not the client.

+1
source

Source: https://habr.com/ru/post/1341858/