Save PL/pgSQL output from PostgreSQL to a CSV file

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

    I've written a little tool called psql2csv that encapsulates the COPY query TO STDOUT pattern, resulting in proper CSV. It's interface is similar to psql.

    psql2csv [OPTIONS] < QUERY
    psql2csv [OPTIONS] QUERY
    

    The query is assumed to be the contents of STDIN, if present, or the last argument. All other arguments are forwarded to psql except for these:

    -h, --help           show help, then exit
    --encoding=ENCODING  use a different encoding than UTF8 (Excel likes LATIN1)
    --no-header          do not output a header
    

提交回复
热议问题