我一直在为其他 StackOverflow 响应而苦苦挣扎。我想将查询的输出保存到本地文本文件 - 只要文本文件在我的本地机器上,它的位置并不重要。
我正在使用的代码:
\COPY (
select month,count(*) as distinct_Count_month
from
(
select UNIQUE_MEM_ID,to_char(transaction_date, 'YYYY-MM') as month
FROM yi_fourmpanel.card_panel WHERE COBRAND_ID = '10006164'
group by UNIQUE_MEM_ID,to_char(transaction_date, 'YYYY-MM')
) a
group by month) TO 'mycsv.csv' WITH CSV HEADER;
此代码的错误是:
<!-- language: none -->
An error occurred when executing the SQL command:
\COPY (
ERROR: syntax error at or near "\"
Position: 1
\COPY (
^
Execution time: 0.08s
(Statement 1 of 2 finished)
An error occurred when executing the SQL command:
select month,count(*) as distinct_Count_month
from
(
select UNIQUE_MEM_ID,to_char(transaction_date, 'YYYY-MM') as month
FROM yi_fourmpanel.card_panel...
ERROR: syntax error at or near ")"
Position: 260
group by month) TO 'mycsv.csv' WITH CSV HEADER
^
Execution time: 0.08s
(Statement 2 of 2 finished)
2 statements failed.
Script execution finished
Total script execution time: 0.16s