lo_put()

用于向大型对象写入数据的函数

lo_put() 是一个用于向大型对象写入数据的系统函数。

lo_put() 添加于 PostgreSQL 9.4

用法

lo_put ( loid oid, offset bigint, data bytea ) → void

数据将被添加到大型对象内的指定偏移量处;如有必要,大型对象将会被扩展。

变更历史

示例

给定以下大型对象

postgres=# SELECT lo_from_bytea(0, '\x48656c6c6f20776f726c64210a');
 lo_from_bytea 
---------------
         16394

postgres=# SELECT *, encode(data, 'escape') FROM pg_largeobject WHERE loid = 16394;
 loid  | pageno |             data             |    encode    
-------+--------+------------------------------+--------------
 16394 |      0 | \x48656c6c6f20776f726c64210a | Hello world!+
       |     

可以使用 lo_put() 如下

postgres=# SELECT lo_put(16394, 6, '\x4561727468');
 lo_put 
--------
 
(1 row)

postgres=# SELECT *, encode(data, 'escape') FROM pg_largeobject WHERE loid = 16394;
 loid  | pageno |             data             |    encode    
-------+--------+------------------------------+--------------
 16394 |      0 | \x48656c6c6f204561727468210a | Hello Earth!+
       |        |                              | 
(1 row)

如有需要,大型对象将被扩展

postgres=# SELECT lo_put(16394, 13, '\x54616b65206d6520746f20796f7572206c656164657221');
 lo_put 
--------
 
(1 row)

postgres=# SELECT loid, pageno, encode(data, 'escape') FROM pg_largeobject WHERE loid = 16394;
 loid  | pageno |         encode          
-------+--------+-------------------------
 16394 |      0 | Hello world!           +
       |        | Take me to your leader!
(1 row)

如果提供的 offset 值超出了当前数据的末尾,中间的空白区域将用 NUL 字节 (\000) 填充

postgres=# SELECT lo_put(16394, 40, '\x424545502042454550');
 lo_put 
--------
 
(1 row)

postgres=# SELECT loid, pageno, encode(data, 'escape') FROM pg_largeobject WHERE loid = 16394;
 loid  | pageno |                      encode                      
-------+--------+--------------------------------------------------
 16394 |      0 | Hello world!                                    +
       |        | Take me to your leader!\000\000\000\000BEEP BEEP
(1 row)

分类

bytea, 大对象, 系统函数

另请参阅

lo_get(), lo_from_bytea()

反馈

对“lo_put()”提交任何评论、建议或更正请 点击此处