我需要将一个文件完整地放入postgres文本字段中,然后将其拉出来最终在磁盘上重新创建该文件。例如,我可以把
{"generation":1,"count":2}
{"generation":2,"count":3}
{"generation":2,"count":3}
进入我的数据库:
SQL (7.4ms) INSERT INTO "data_dumps" ("data", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["data", " {\"generation\":1,\"count\":2}\n {\"generation\":2,\"count\":3}\n {\"generation\":2,\"count\":3}\n"], ["created_at", "2015-10-14 21:03:40.019299"], ["updated_at", "2015-10-14 21:03:40.019299"]]
(13.3ms) COMMIT
然而,当我从命令行查询它时,每行都被分成一行。所以这个:
$ echo 'COPY (SELECT "data_dumps"."data" FROM "data_dumps" ORDER BY created_at DESC LIMIT 1) TO STDOUT' | psql triage_development > tmp/test; cat tmp/test
给我输出
{"generation":1,"count":2}\n {"generation":2,"count":3}\n {"generation":2,"count":3}\n
我不能使用psql标志。
我的问题是:如何使用postgres输出没有标题的单个大文本字段并支持多行输出?