使用Python客户端。
我正在恢复连接,然后提交带有硬编码参数 arg 数据的插入语句。但是出现错误。
from crate import client
con = client.connect("http://webservicesbigmac.richmond.edu:4200")
cursor = con.cursor()
print cursor
cursor.execute("INSERT INTO logs (client_ip) VALUES (?)", ("66.249.67.49"))
我可以在崩溃客户端中运行此查询并且它可以工作
cr> 插入日志 (client_ip) 值 ('66.249.67.49');
插入正常,1 行受影响(0.001 秒)
我确信我做错了什么,只是不确定它是什么。
这个堆栈跟踪
<crate.client.cursor.Cursor object at 0x10e40bcd0>
Traceback (most recent call last):
File "/Users/epalmer/projects/cratedbload/sqlload2.py", line 11, in <module>
cursor.execute("INSERT INTO logs (client_ip) VALUES (?)", ("66.249.67.49"))
File "/Library/Python/2.7/site-packages/crate/client/cursor.py", line 51, in execute
self._result = self.connection.client.sql(sql, parameters, bulk_parameters)
File "/Library/Python/2.7/site-packages/crate/client/http.py", line 202, in sql
content = self._json_request('POST', self.path, data=data)
File "/Library/Python/2.7/site-packages/crate/client/http.py", line 362, in _json_request
self._raise_for_status(response)
File "/Library/Python/2.7/site-packages/crate/client/http.py", line 348, in _raise_for_status
raise ProgrammingError(error.get('message', ''), error_trace=error_trace)
crate.client.exceptions.ProgrammingError: SQLActionException[Failed to parse source [{"args": "66.249.67.49", "stmt": "INSERT INTO logs (client_ip) VALUES (?)"}]]
最佳答案
我猜测(从未使用过 cratedata),但来自 select examples 之一,看来绑定(bind)变量列表需要是一个元组。您只传递一个值 - 尝试:("66.249.67.49", )
注意逗号
关于python - 无法从 python 客户端插入 crateb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25857085/