lo_from_bytea() 是一个用于创建 大对象 并用数据填充它的系统函数。
lo_from_bytea() 在 PostgreSQL 9.4 中添加。
用法
lo_from_bytea (loidoid,databytea) →oid
如果 loid 为 0,则会自动分配一个 OID,否则将使用提供的 OID。
成功时,返回创建的大对象的 OID;否则,会引发错误。
变更历史
- PostgreSQL 9.4
- 添加于(提交 c50b7c09)
示例
lo_from_bytea() 的基本用法示例
postgres=# SELECT lo_from_bytea(0, '\x48656c6c6f20776f726c64210a');
lo_from_bytea
---------------
16388
(1 row)
postgres=# SELECT * FROM pg_largeobject;
loid | pageno | data
-------+--------+------------------------------
16388 | 0 | \x48656c6c6f20776f726c64210a
(1 row)
尝试使用现有 OID 创建大对象
postgres=# SELECT lo_from_bytea(16388, '\xdeadbeef'); ERROR: duplicate key value violates unique constraint "pg_largeobject_metadata_oid_index" DETAIL: Key (oid)=(16388) already exists.
参考资料
- PostgreSQL文档: SQL方式的大对象函数
