【发布时间】:2018-06-07 19:02:50
【问题描述】:
我正在使用 Jupyter 笔记本来处理一些带有 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
【问题讨论】:
-
您的旧版本did not support
COPY命令中的选择语句。 如果您使用的是过时版本,您还应该阅读该版本的手册,而不是较新版本的手册。您应该现在升级到受支持和维护的版本。 -
请升级您的 Postgres。我们现在有 10 个,距离第 8 版已经有很多年了。
-
我正在使用 Jupyter Notebook + Python 3.4+ psycopg2(它允许我进行 postgresql 查询)。如何升级?有没有将数据导出到 csv 的选项?
标签: postgresql export-to-csv psycopg2 postgresql-8.0