我正在尝试使用\ copy将SQL查询的结果复制到CSV文件中。但是,我在TO遇到语法错误,我无法找出原因。
请注意,执行SQL查询可在psql中运行,但是当我尝试将查询结果从\ copy导出到CSV文件时会收到错误消息。
\COPY
(SELECT
event_number,
event_type,
unit,
received,
split_part(entry::TEXT,' ',1)entry_year,
split_part(entry::TEXT,' ',2)entry_time,
split_part(dispatch::TEXT,' ',1)dispatch_year,
split_part(dispatch::TEXT,' ',2)dispatch_time,
split_part(ack::TEXT,' ',1)ack_year,
split_part(ack::TEXT,' ',2)ack_time,
enroute,
split_part(onscene::TEXT,' ',1)onscene_year,
split_part(onscene::TEXT,' ',2)onscene_time,
split_part(to_hospital::TEXT,' ',1)to_hospital_year,
split_part(to_hospital::TEXT,' ',2)to_hospital_time,
at_hospital,
return_to_qrtrs,
split_part(available_in_qrtrs::TEXT,' ',1)available_in_qrtrs_year,
split_part(available_in_qrtrs::TEXT,' ',2)available_in_qrtrs_time,
split_part(last_col::TEXT,' ',1)last_col_year,
split_part(last_col::TEXT,' ',2)last_col_time
FROM import.oems)
TO '/Users/ctoner/Desktop/oems/foia_190910/formatoems.csv' WITH CSV DELIMETER ',' HEADER;
ERROR: syntax error at or near "TO"
LINE 24: TO '/Users/ctoner/Desktop/oems/foia_190910/formatoems.csv'
答案 0 :(得分:0)
查询中有错字
第TO '/Users/ctoner/Desktop/oems/foia_190910/formatoems.csv' WITH CSV DELIMETER ',' HEADER;
行
将DELIMETER
替换为DELIMITER
此外,文档说该文件应该已经存在于服务器上。