【发布时间】:2015-06-08 14:15:17
【问题描述】:
我正在使用PostgreSQL 9.2。
This blog entry by Grace Batumbya 提供从bytea 到oid 的转换。
create or replace function blob_write(lbytea bytea)
returns oid
volatile
language plpgsql as
$f$
declare
loid oid;
lfd integer;
lsize integer;
begin
if(lbytea is null) then
return null;
end if;
loid := lo_create(0);
lfd := lo_open(loid,131072);
lsize := lowrite(lfd,lbytea);
perform lo_close(lfd);
return loid;
end;
$f$;
CREATE CAST (bytea AS oid) WITH FUNCTION blob_write(bytea) AS ASSIGNMENT;
CREATE TABLE bytea_to_lo (
largeObj lo
);
我不明白为什么要创建bytea_to_lo 表? PostgreSQL将如何使用它?
【问题讨论】:
-
所以你“找到”了?你能链接到源吗?
-
@ErwinBrandstetter 当然,我是从 there 那里得到的。
-
这是一个非常糟糕的 IMO 主意,应该使用显式函数调用来代替。
标签: sql postgresql types casting blob