How to export query results to excel file using psql command in postgresql

Started by Naveen Kumarover 5 years ago4 messagesgeneral
Jump to latest
#1Naveen Kumar
naveenmcp@gmail.com

How to export query results to excel file using psql command in postgresql

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Naveen Kumar (#1)
Re: How to export query results to excel file using psql command in postgresql

Hi

čt 13. 8. 2020 v 16:10 odesílatel Naveen Kumar <naveenmcp@gmail.com> napsal:

How to export query results to excel file using psql command in postgresql

Excel can import csv file

so you can

for Postgres 12

\pset format csv
\o path_to_file
select * from ...

or for older postgres

\copy (select * from ...) to path_to_file CSV HEADER

Regards

Pavel

#3Paul Förster
paul.foerster@gmail.com
In reply to: Naveen Kumar (#1)
Re: How to export query results to excel file using psql command in postgresql

Hi Naveen,

On 13. Aug, 2020, at 16:10, Naveen Kumar <naveenmcp@gmail.com> wrote:

How to export query results to excel file using psql command in postgresql

use the "copy" command along with its CSV output setting. Then open the CSV file with Excel.

Look here:

https://www.postgresqltutorial.com/export-postgresql-table-to-csv-file/

https://www.postgresql.org/docs/current/sql-copy.html

Cheers,
Paul

#4Adrian Klaver
adrian.klaver@aklaver.com
In reply to: Naveen Kumar (#1)
Re: How to export query results to excel file using psql command in postgresql

On 8/13/20 7:10 AM, Naveen Kumar wrote:

How to export query results to excel file using psql command in postgresql

You can't. You can export to CSV that you could then import into Excel.

See:

https://www.postgresql.org/docs/12/app-psql.html

\copy

--
Adrian Klaver
adrian.klaver@aklaver.com