我可以在数据库服务器上复制 Postgresql 大对象吗?

发布于 2024-10-19 15:58:51 字数 144 浏览 3 评论 0原文

我在一个大对象中有数据,现在我想复制它,这样我就可以在保留原始副本的同时附加到它。是否有任何 JDBC 调用或 SQL 语句可以用来导致这种情况发生?

从我找到的每个资源来看,我似乎必须将所有数据实际读取到客户端并再次写出才能获取副本。我更愿意节省往返路程。

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

From every resource I have found, it seems I have to actually read all the data to my client and write it out again to get the copy. I'd much prefer to save the round trip.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

狼性发作 2024-10-26 15:58:52

如果您知道大型对象的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 是大对象的已知 oid
my_new_oid 是第一个插入语句返回的 oid

pg_large_object参考
对象类型标识符 (oid) 参考

A large object can be copied/cloned with two queries 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 the large object's known oid
my_new_oid is the oid returned by the first insert statement

pg_large_object reference
Object Type Identifier (oid) reference

迷荒 2024-10-26 15:58:52

查看服务器端 lo_import 和 lo_export 函数。您必须将数据从数据库移动到文件系统,然后再移回,但至少这是服务器的文件系统,而不是客户端的文件系统。

Have a look at the server-side lo_import and lo_export functions. You will have to move the data from the database to the filesystem and back again, but at least it's the server's filesystem, not the client's.

昔日梦未散 2024-10-26 15:58:52

自 9.4 起可用:使用 lo_from_bytealo_get

SELECT lo_from_bytea(0, lo_get(<the large object you want to clone>));

这会将创建的大对象的所有者设置为当前用户,因此您可能必须更改之后大对象的所有者:

ALTER LARGE OBJECT <returned oid of the newly created lo> OWNER TO <username>;

参考:

https://www.postgresql。 org/docs/14/lo-funcs.html

https:// /www.postgresql.org/docs/14/sql-alterlargeobject.html

Available since 9.4: use lo_from_bytea and lo_get:

SELECT lo_from_bytea(0, lo_get(<the large object you want to clone>));

This sets the owner of the created large object as the current user, so you may have to alter the owner of the large object afterwards:

ALTER LARGE OBJECT <returned oid of the newly created lo> OWNER TO <username>;

Reference:

https://www.postgresql.org/docs/14/lo-funcs.html

https://www.postgresql.org/docs/14/sql-alterlargeobject.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文