PostgreSQL查询输出为Excel文件 [英] PostgreSQL query output as a excel file

查看:81
本文介绍了PostgreSQL查询输出为Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将psql查询的结果另存为Excel文件.即,我有一个名为5列的公司表.我要执行查询,

I want to save the result of a psql query as an Excel file. ie, I have a table named company with 5 column. I want to execute the query,

SELECT column_1,
       column_2,
     FROM company; 

我只想将此查询的结果另存为Excel文件.在PostgreSQL中可以吗?如果是的话,请解释一下.

And I just want to save the result of this query as a Excel file. Is it possible in PostgreSQL? If yes then please explain it.

谢谢...

推荐答案

您可以使用csv保存数据并在Excel中打开/使用它们.语法类似于:

You could use csv to save your data and open/work with them in Excel. Syntax would be something like:

Copy (SELECT column_1,
             column_2,
      FROM company; 
     ) 
To '/tmp/test.csv' With CSV;

此查询将在服务器上运行.您还可以使用客户端上运行的 \ query 并在本地保存数据.另请参见另一个 SE问题

This query would run on server. You could also make usage of \query which is running on your client and saving the data locally. See also another SE question

这篇关于PostgreSQL查询输出为Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆