Save PL/pgSQL output from PostgreSQL to a CSV file

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

    psql can do this for you:

    edd@ron:~$ psql -d beancounter -t -A -F"," \
                    -c "select date, symbol, day_close " \
                       "from stockprices where symbol like 'I%' " \
                       "and date >= '2009-10-02'"
    2009-10-02,IBM,119.02
    2009-10-02,IEF,92.77
    2009-10-02,IEV,37.05
    2009-10-02,IJH,66.18
    2009-10-02,IJR,50.33
    2009-10-02,ILF,42.24
    2009-10-02,INTC,18.97
    2009-10-02,IP,21.39
    edd@ron:~$
    

    See man psql for help on the options used here.

提交回复
热议问题