Save PL/pgSQL output from PostgreSQL to a CSV file

后端 未结 18 2281
名媛妹妹
名媛妹妹 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:24

    If you're interested in all the columns of a particular table along with headers, you can use

    COPY table TO '/some_destdir/mycsv.csv' WITH CSV HEADER;
    

    This is a tiny bit simpler than

    COPY (SELECT * FROM table) TO '/some_destdir/mycsv.csv' WITH CSV HEADER;
    

    which, to the best of my knowledge, are equivalent.

提交回复
热议问题