↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

支持中的版本: 当前版本 (18) / 17 / 16 / 15 / 14
开发中的版本: 19 / 20devel
已结束支持的版本: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3 / 7.2 / 7.1
历史版本。 PostgreSQL 9.0 已结束支持。 2015-10-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。

报告文档问题

阅读 上游文档. 反馈更正前请先核对 当前版本手册.