![](/img/trans.png)
[英]Given a XML file, I am writing Bash to parse it, but need to create a header and break up a date string?
[英]I am writing postgresql data to file using bash and psql. I need the column headers written to the output file
腳本:
#!/bin/bash/
PGPASSWORD='*******' psql -h host_name server_name user_name -t -A -F "," -c "select b.id AS booking_id, b.hotel_id as hotel_id, b.invoice_no as invoice_no, b.guest_id as guest_id from bookings b" > /home/ubuntu/scripts/food_suggest/automate/pgsql_data.csv;
電流輸出:
12345, 1111, ABCD1234, A111
12346, 1112, ABCD1235, A112 ...
要求的輸出:
booking_id, hotel_id, invoice_no, guest_id 12345, 1111, ABCD1234, A111 12346, 1112, ABCD1235, A112 ...
我使用簡單的COPY命令從bash + psql進行操作FORCE QUOTE
如果您有逗號或字符串中的字符, 請使用params CSV HEADER
或FORCE QUOTE
否則就可以了。
對於json導出,我使用COPY (select row_to_json(...
沒有CSV
參數。兩者都很好。我將其用於從PG導出到Bigquery。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.