历史版本。 PostgreSQL 9.3 已结束支持。 2018-11-08. 请参阅 当前版本手册.
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的名称调用这些函数。