我正在使用 Jupyter notebook 来处理一些带有 postgresql 的数据库 我有以下实例:
import pandas as pd
import (other packages)
conn_string= % I can't show this, but this is ok
conn = psycopg2.connect(conn_string)
cursor=conn.cursor
query= """ copy (select col1,col2 from Table where col3=a_parameter
and col4=b_parameter) to '/tmp/test.csv' with csv """
pd.read_sql(query,conn)
但是我得到了这个错误:
**ProgrammingError: syntax error at or near "("
LINE 1: COPY (select col1,col2 from Table where col3...**
^
为什么复制语句有错误? 我正在使用 Postresql 8.0.2
最佳答案
像这样:
import csv
my_file_csv = my_folder + "\Report_Trip_Day_" + my_opr + "_" + my_local_database + ".csv"
out = csv.writer(open(my_file_csv, "w", newline=''), delimiter=',', quoting=csv.QUOTE_ALL)
out.writerow(colnames)
for row in my_xls_report_table:
out.writerow(row)
关于postgresql - "("postgresql + Python 处或附近的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50748504/