Car*_*ano 8 database postgresql export psql
我bytea
在PostgreSQL DB中有一个包含PDF文件的列.如何使用导出该文件psql
?
我试过了:
psql -U <USER> -h <HOST> -p <PORT> -d <DB> -c "\copy (select <column> from <table> where <column> = <id>) to STDOUT with BINARY;" > output.pdf
Run Code Online (Sandbox Code Playgroud)
这样可以保存文件,我可以在PDF阅读器中打开它.但是当我检查文件时hexdump -C output.pdf | head
,我看到它有一个标题开头PGCOPY
.
如何导出没有PGCOPY
标题的文件?
Car*_*ano 11
我使用Postgre的encode()
十六进制和bash xxd
从十六进制解码:
psql -U <USER> -h <HOST> -p <PORT> -d <DB> -c "\copy (SELECT encode(<column>, 'hex') from <table> where <column> = <id>) to STDOUT" | xxd -p -r > output
Run Code Online (Sandbox Code Playgroud)
文件看起来不错:
$ hexdump -C output | head -n 5
00000000 25 50 44 46 2d 31 2e 36 0d 25 e2 e3 cf d3 0d 0a |%PDF-1.6.%......|
00000010 38 37 20 30 20 6f 62 6a 0d 3c 3c 2f 4c 69 6e 65 |87 0 obj.<</Line|
00000020 61 72 69 7a 65 64 20 31 2f 4c 20 31 30 32 33 32 |arized 1/L 10232|
00000030 32 35 2f 4f 20 38 39 2f 45 20 31 35 36 35 30 36 |25/O 89/E 156506|
00000040 2f 4e 20 31 37 2f 54 20 31 30 32 32 38 30 36 2f |/N 17/T 1022806/|
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3946 次 |
最近记录: |