How to download Postgres bytea column as file

前端 未结 6 1802
甜味超标
甜味超标 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 07:04

    Here's the simplest thing I could come up with:

    psql -qAt "select encode(file,'base64') from files limit 1" | base64 -d
    

    The -qAt is important as it strips off any formatting of the output. These options are available inside the psql shell, too.

提交回复
热议问题