我可以在数据库服务器上复制 Postgresql 大对象吗?
我在一个大对象中有数据,现在我想复制它,这样我就可以在保留原始副本的同时附加到它。是否有任何 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您知道大型对象的
oid
,则可以使用两个查询来复制/克隆大型对象。my_old_oid
是大对象的已知 oidmy_new_oid
是第一个插入语句返回的 oidpg_large_object参考
对象类型标识符 (oid) 参考
A large object can be copied/cloned with two queries if you know its
oid
.my_old_oid
is the large object's known oidmy_new_oid
is the oid returned by the first insert statementpg_large_object reference
Object Type Identifier (oid) reference
查看服务器端 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.
自 9.4 起可用:使用 lo_from_bytea 和 lo_get:
这会将创建的大对象的所有者设置为当前用户,因此您可能必须更改之后大对象的所有者:
参考:
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:
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:
Reference:
https://www.postgresql.org/docs/14/lo-funcs.html
https://www.postgresql.org/docs/14/sql-alterlargeobject.html