0
在Ubuntu 16.04上使用python 3.5和mysql 5.7.18,我無法在executemany語句中使用ST_GEOMFROMTEXT函數。無法使用executemany執行ST_GEOMFROMTEXT
使用此代碼:
print(query)
print(add_vals[-1:])
zip_cursor.executemany(query, add_vals[-1:])
我得到以下輸出:
INSERT INTO zipcodes (zipcode, name, area, pop, emp, emp_pay, households, location) VALUES (%s,%s,%s,%s,%s,%s,%s,%s);
[["'54517'", "'CLAM LAKE, WI'", 201.441702, 112, 10, 600, 59, "ST_GEOMFROMTEXT('POINT(46.145917 -90.930676)')"]]
Traceback (most recent call last):
File "zip_parse.py", line 319, in <module>
main()
File "zip_parse.py", line 32, in main
insert_data(zip_db, zip_cursor, data)
File "zip_parse.py", line 160, in insert_data
zip_cursor.executemany(query, add_vals[-1:])
File "/usr/local/lib/python3.5/dist-packages/mysql/connector/cursor.py", line 618, in executemany
return self.execute(stmt)
File "/usr/local/lib/python3.5/dist-packages/mysql/connector/cursor.py", line 515, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "/usr/local/lib/python3.5/dist-packages/mysql/connector/connection.py", line 488, in cmd_query
result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
File "/usr/local/lib/python3.5/dist-packages/mysql/connector/connection.py", line 395, in _handle_result
raise errors.get_exception(packet)
mysql.connector.errors.DataError: 1416 (22003): Cannot get geometry object from data you send to the GEOMETRY field
然而,通過聲明似乎在複製到mysql命令行就好了去:
mysql> INSERT INTO zipcodes (zipcode, name, area, pop, emp, emp_pay, households, location) VALUES ('54517','CLAM LAKE, WI',201.441702,112,10,600,59,ST_GEOMFROMTEXT('POINT(46.145917 -90.930676)'));
Query OK, 1 row affected (0.05 sec)
過去我廣泛使用了ST_GEOMFROMTEXT函數,而且我非常自信這是將空間數據添加到幾何字段(字段'位置'具有類型'POINT')的正確方法。正如所證明的那樣,它不需要引用它來在命令行上工作(這經常是我的經驗中的焦點)。
任何想法爲什麼這不與執行許多?