9.3 9.4 9.5 9.6 10 11 12 13
阿里云PostgreSQL 问题报告 纠错本页面

32.4. 服务器端函数

还有一些对应上面那些客户端函数的服务器端函数, 可以在SQL命令里使用;实际上, 大多数客户端函数都只是服务器端函数的等效接口。这些服务器端函数中, 通过SQL命令调用的实际有用的是lo_creat, lo_createlo_unlinklo_importlo_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_importlo_export函数和客户端的那几个有着显著的不同。 这两个函数在服务器的文件系统里读写文件, 使用数据库所有者的权限进行。 因此,只有超级用户才能使用他们。相比之下,客户端的输入和输出函数在客户端的文件系统里读写文件, 使用客户端程序的权限。客户端函数不需要超级用户权限。

lo_readlo_write的功能通过服务器端调用可用, 但是服务器端函数名不同于客户端接口,因为他们不包含下划线。你必须作为loreadlowrite 调用这些函数。

<
/BODY >