【发布时间】:2018-05-10 15:31:00
【问题描述】:
所以这是一个相对简单的问题。我有一个 postgresql 表,我需要将其转储到本地计算机上的 xml 文件中。我已经阅读了https://www.postgresql.org/docs/current/static/functions-xml.html 和https://www.postgresql.org/docs/9.4/static/sql-copy.html 的所有文档,并通过 psql 命令行提出了以下命令:
COPY (SELECT table_to_xml(SELECT FROM Database public.'table', true, false, '')) to 'C:/users/me/file.xml';
但是,我在“FROM”处或附近不断收到语法错误。在过去的一个小时里,我搜索了每一个看起来有用的 SO 链接 (Postgresql tables exists, but getting "relation does not exist" when querying | Cannot simply use PostgreSQL table name ("relation does not exist") | using copy in postgresql? | Postgres Data to XML) 和每一个听起来很像我需要的 YouTube 视频,但无济于事。我尝试过使用和不使用 FROM 语句,尝试在 FROM 前面使用 SELECT *,等等......没有运气。一定有一些非常简单的东西我错过了。有什么想法吗?
【问题讨论】:
-
您能否提供以下输出:SELECT * FROM information_schema.tables where table_name = 'your_table_name'
-
很好奇,
table_to_xml()查询在复制到文本文件之前是否有效? -
@Vivek 当我在我的 PGAdmin 4 上执行查询 SELECT * FROM information_schema.tables where table_name = 'your_table_name' 时,我得到以下结果: 一个有很多标题的表,只有一行。标题是table_catalog(数据库名称),table_schema(公共),table_name(我的表的名称),table_type(BASE TABLE)等......其余为空
-
没有将 public 作为数据库名称,而是将返回的值作为数据库,这一切都在尝试,因为我现在没有 pg 会话
-
@Vivek 好消息和坏消息...好消息是我尝试按照您的建议执行命令 COPY (SELECT table_to_xml(Database.'table', true, false, ''))到'C:/users/me/file.xml';它并没有给我一个错误......但是没有创建文件,并且从我的任务管理器的外观来看,没有其他任何事情发生。
标签: sql xml database postgresql