vertica-python COPY LOCAL 时出错

vertica-python Error on COPY LOCAL

我在 Vertica 7.1 上的 python 中将此代码用于 'COPY LOCAL':

conn_info = {'host': '192.168.1.1', 'port': 5433, 'user': 'dbadmin', 'password': 'xxxxxx', 'database': 'db'}
connection = vertica_python.connect(**conn_info)
cur = connection.cursor()
file_name="/tmp/tmp_file"
temp_file = open(file_name,"w")
temp_file .write(records)
temp_file.close()
os.system('gzip -cvf9 %s > %s.gz'%(file_name,file_name))
qr="copy tmp_table(int_id, int_timestamp, ... ) from local '%s' GZIP delimiter ';' RECORD TERMINATOR E'\r' NULL  '\N';"%(file_name+'.gz')
cur.execute(qr)

但我现在想在 Vertica 9.0.1 上做同样的事情,但我收到了这个错误:

Traceback (most recent call last):

File "collector_as.py", line 264, in

cur.execute(qr)

File "/usr/local/lib/python2.7/dist-packages/vertica_python/vertica/cursor.py", line 126, in execute

self.connection.process_message(self._message)

File "/usr/local/lib/python2.7/dist-packages/vertica_python/vertica/connection.py", line 232, in process_message

raise errors.MessageError("Unhandled message: {0}".format(message))

MessageError: Unhandled message:

我的vertica-python 版本:

pip freeze | grep vertica  -->  vertica-python==0.7.3

------------------------

另外 我尝试了来自 VERTICA 的新 vertica-db-client (vertica-client-9.0.1-4.x86_64.tar.gz)
我的 vertica-db-client 版本:

pip freeze | grep vertica  -->  vertica-db-client==9.0.1.4

我收到了这个错误:

Traceback (most recent call last):

File "collector_as.py", line 265, in

cur.execute(qr)

NotSupportedError: COPY LOCAL is not supported

当使用 vertica-python 执行 COPY 命令时,您使用 cur.copy(...) 方法。

游标的复制方法有两个参数

  1. 复制命令
  2. 要复制的文件

此外,您使用 FROM STDIN

而不是 FROM LOCAL
qr="copy tmp_table(int_id, int_timestamp, ... ) from STDIN GZIP delimiter ';' RECORD TERMINATOR E'\r' NULL  '\N';"
cur.copy(qr, file_name+'.gz')

如果您使用的是 vsql——例如——那么您使用 FROM LOCAL 的语法是正确的,但是 vertica-python 基本上将给定的文件作为第二个参数并将其通过管道传输到副本中作为 STDIN 命令。