gpt4 book ai didi

database - 如何将 *.dump 文件中的表格提取到 CSV 文件中

转载 作者:搜寻专家 更新时间:2023-10-30 19:41:34 25 4
gpt4 key购买 nike

我有一个 *.dump 文件(postgresql 转储),我想将 my_table 输出到 my_table.csv。有没有比 pg_restore -t my_table db.dump > my_table.txt 然后编写脚本从输出创建 CSV 更好的方法?

最佳答案

pg_restore --data-only -t my_table db.dump 的输出基本上是 制表符分隔的无标题表格文本,带有一些注释和一些额外的命令。使用 perlawk 等工具将其转换为 csv 的脚本会非常简单。

也就是说,我个人会:

  • 将表恢复到为此目的创建的临时数据库。如果该表依赖于自定义类型、函数、序列等,您也需要恢复它们。

  • psql 中,\copy the_table TO 'some_file.csv' WITH (FORMAT CSV, HEADER ON)

这样你就可以control the representation of nulls and lots more .

关于database - 如何将 *.dump 文件中的表格提取到 CSV 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18114333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com