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()" 的评论、建议或更正 此处