Save PL/pgSQL output from PostgreSQL to a CSV file

后端 未结 18 2028
名媛妹妹
名媛妹妹 2020-11-22 11:56

What is the easiest way to save PL/pgSQL output from a PostgreSQL database to a CSV file?

I\'m using PostgreSQL 8.4 with pgAdmin III and PSQL plugin where I run que

18条回答
  •  难免孤独
    2020-11-22 12:21

    I tried several things but few of them were able to give me the desired CSV with header details.

    Here is what worked for me.

    psql -d dbame -U username \
      -c "COPY ( SELECT * FROM TABLE ) TO STDOUT WITH CSV HEADER " > \
      OUTPUT_CSV_FILE.csv
    

提交回复
热议问题