我试图通过insert查询将存储为python变量的纬度和经度插入PostgreSQL中的表中。除了我试过的方法之外,还有什么建议吗?在
我首先尝试了insert查询,如下所示-
这是桌子:
cur.execute('''CREATE TABLE AccidentList (
accidentId SERIAL PRIMARY KEY,
cameraGeoLocation POINT,
accidentTimeStamp TIMESTAMPTZ);''')
尝试1:
^{pr2}$错误:
LINE 1: ...ist (cameraGeoLocation,accidentTimeStamp) VALUES (13.0843, 8... ^
HINT: You will need to rewrite or cast the expression.
尝试2:
query = "INSERT INTO AccidentList (cameraGeoLocation,accidentTimeStamp)
VALUES(cameraGeoLocation::POINT, accidentTimeStamp::TIMESTAMPTZ);"
data = ((lat,lon),ts)
cur.execute(query,data)
错误:
LINE 1: ...List (cameraGeoLocation,accidentTimeStamp) VALUES(cameraGeoL... ^
HINT: There is a column named "camerageolocation" in table "accidentlist", but it cannot be referenced from this part of the query.
尝试3:
query = "INSERT INTO AccidentList (camerageolocation ,accidenttimestamp) VALUES(%s::POINT, %s);"
data = (POINT(lat,lon),ts)
cur.execute(query,data)
错误:
cur.execute(query,data) psycopg2.ProgrammingError: cannot cast type record to point LINE 1: ...tion ,accidenttimestamp) VALUES((13.0843, 80.2805)::POINT, '...
单引号你的第三次尝试。 这是有效的:
SELECT '(13.0843, 80.2805)'::POINT
相关问题 更多 >
编程相关推荐