On this page
34.4. 服务器端功能
Table 34.1中列出了专门为从 SQL 处理大型对象而定制的服务器端功能。
表 34.1 面向 SQL 的大对象函数
还有其他服务器端功能,它们与前面描述的每个 Client 端功能相对应。实际上,在大多数情况下,Client 端功能只是与等效服务器端功能的接口。通过 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
函数的行为与其 Client 端类似物有很大不同。这两个函数使用数据库拥有的用户的权限在服务器的文件系统中读写文件。因此,它们的使用仅限于超级用户。相反,Client 端导入和导出功能使用 Client 端程序的权限读取和写入 Client 端文件系统中的文件。Client 端功能不需要超级用户特权。
lo_read
和lo_write
的功能也可以通过服务器端调用来使用,但是服务器端函数的名称与 Client 端接口的不同之处在于它们不包含下划线。您必须将这些函数称为loread
和lowrite
。