How to download Postgres bytea column as file

前端 未结 6 1815
甜味超标
甜味超标 2020-12-24 06:13

Currently, i have a number of files stored in postgres 8.4 as bytea. The file types are .doc, .odt, .pdf, .txt and etc.

May i know how to download all the file store

6条回答
  •  清歌不尽
    2020-12-24 06:48

    DO $$ 
    DECLARE   
       l_lob_id OID;
       r record; BEGIN
    
      for r in
        select data, filename from bytea_table
    
       LOOP
        l_lob_id:=lo_from_bytea(0,r.data);
        PERFORM lo_export(l_lob_id,'/home/...'||r.filename);
        PERFORM lo_unlink(l_lob_id);   
        END LOOP;
    
    END; $$
    

提交回复
热议问题