2017-06-18 79 views
1

目前,我可以簡單地運行如何防止PSQL輸出行數?

psql -A -t -F'\t' -c "SELECT ...;" > myfile.csv 

但是它在文件的結尾,則返回的行數幾乎得到PSQL一個CSV。我可以修復他與head -n -1

psql -A -t -F'\t' | head -n -1 | -c "SELECT ...;" 

但與非常大的文件似乎是矯枉過正。這裏是psql中的一個標誌,我可以關閉返回的記錄數量?

+1

可能'--pset =「footer = off」'(我無法測試)。 –

+0

This works,please post this as answer – ForeverConfused

+1

Oh,there are better answers [here](https://stackoverflow.com/questions/1517635/save-pl-pgsql-output-from-postgresql-to-a-csv-文件):) –

回答

3

有很多從PostrgeSQL獲取CSV的常用方法(請參閱,例如this question)。但是,在使用Redshift時,並非所有這些方法都適用,部分原因是Amazon Redshift基於Postgres 8.0.2。

可以嘗試使用--pset="footer=off"選項來防止psql輸出行數。另請諮詢8.0.26 psql documentation