postgresql 插入圖片

CREATE OR REPLACE FUNCTION bytea_import(p_path text, p_result out bytea) LANGUAGE plpgsql AS $$

DECLARE

    l_oid oid;

    rec record;

BEGIN

    p_result := '';

  select lo_import(p_path) into l_oid;

  for rec in ( select data from pg_largeobject where loid = l_oid order by pageno )

 

  loop

        p_result = p_result || rec.data;

    end loop;

    perform lo_unlink(l_oid);

END; $$ ;

 

create table test1(zjhm varchar(100), tp bytea);

 

insert into test1(zjhm, tp) values ('362232',

(select bytea_import('D:\\test.png') ) );


select zjhm, '11' as xm, tp from test1

發佈了62 篇原創文章 · 獲贊 7 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章