PostgreSQL query output as a excel file

人走茶凉 提交于 2020-12-26 09:40:08

问题


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; 

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.

Thank you......


回答1:


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;

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



来源:https://stackoverflow.com/questions/25987226/postgresql-query-output-as-a-excel-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!