选择 打开 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

受支持版本: 当前版本 (18) / 17 / 16 / 15 / 14
测试与开发版本: 19 / devel
不受支持的版本: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0
历史版本PostgreSQL 9.3 已于 2018 年 11 月结束社区维护,本页译文保留供仍在使用旧版本的读者参考。新系统请看当前版本

32.4. 服务器端函数 #

有一些可通过 SQL 调用的服务器端函数,它们与上文所述的各个客户端函数相对应;实际上,大多数客户端函数只是等价服务器端函数的接口。通过 SQL 命令调用真正有用的是 lo_creatlo_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的名称调用这些函数。

提交更正

译文有误、术语不当或页面显示问题,请到译文仓库 pgsty/pgdoc 报告译文问题。 英文原文本身的问题,请在当前版本的对应页面向上游反馈;上游不再修订已结束维护的版本。