我通过终端中的psql运行以下远程postgresql数据库的查询:
\copy (SELECT cylinders.reduction, cylinders.name, print_suppliers.name FROM cylinders, jobs, print_suppliers WHERE cylinders.id = jobs.cylinder_id AND print_suppliers.id = cylinders.print_supplier_id AND jobs.id = 015983) TO '/Users/alex/result_sql.csv' WITH CSV HEADER
并获取保存在我的高清上的正确csv文件。但是,我需要在本地保存一个xml文件并尝试这个:
\copy SELECT query_to_xml('SELECT cylinders.reduction, cylinders.name, print_suppliers.name FROM cylinders, jobs, print_suppliers WHERE cylinders.id = jobs.cylinder_id AND print_suppliers.id = cylinders.print_supplier_id AND jobs.id = 015983', true, true, '') TO '/Users/alex/result_sql.xml'
但是我收到了这个错误:
\ copy:在" query_to_xml"解析错误。没有副本......我是 获得完美的xml输出。
有没有办法将终端的xml输出保存到我的计算机上?
谢谢,Alex
答案 0 :(得分:1)
复制后需要额外的括号才能从查询中复制,而不是表格。像这里:
\copy (
SELECT query_to_xml(
'SELECT cylinders.reduction, cylinders.name, print_suppliers.name
FROM cylinders, jobs, print_suppliers
WHERE cylinders.id = jobs.cylinder_id AND print_suppliers.id = cylinders.print_supplier_id AND jobs.id = 015983'
, true, true, ''
)
)
TO '/Users/alex/result_sql.xml'