历史版本。 PostgreSQL 9.2 已结束支持。 2017-11-09. 请参阅 当前版本手册.
32.4. 服务器端函数 #
前面介绍的每个客户端函数都有对应的服务器端函数可以通过 SQL 调用;实际上,大多数客户端函数都只是等价服务器端函数的接口。通过 SQL 命令调用真正有用的是
lo_creat、lo_create、lo_unlink、lo_import 和
lo_export。下面是它们的使用示例:
CREATE TABLE image (
name text,
raster oid
);
SELECT lo_creat(-1); -- returns OID of new, empty large object
SELECT lo_create(43213); -- attempts to create large object with OID 43213
SELECT lo_unlink(173454); -- deletes large object with OID 173454
INSERT INTO image (name, raster)
VALUES ('beautiful image', lo_import('/etc/motd'));
INSERT INTO image (name, raster) -- same as above, but specify OID to use
VALUES ('beautiful image', lo_import('/etc/motd', 68583));
SELECT lo_export(image.raster, '/tmp/motd') FROM image
WHERE name = 'beautiful image'; 服务器端 lo_import 和 lo_export 函数的行为与客户端对应函数有很大不同。这两个函数使用运行数据库服务器的用户的权限,读写服务器文件系统中的文件,因此它们的用途受限制。相比之下,客户端导入和导出函数读写客户端文件系统中的文件,使用客户端程序的权限。客户端函数不要求任何特殊的数据库权限。
lo_read 和 lo_write 的功能也可以通过服务器端调用获得,但服务器端函数名与客户端接口不同:不包含下划线。必须将这些函数调用为loread 和 lowrite。