无法将INSERT查询中的点数据类型强制转换为PostgreSQL。经度,需要插入制表符的纬度

2024-06-26 17:53:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过insert查询将存储为python变量的纬度和经度插入PostgreSQL中的表中。除了我试过的方法之外,还有什么建议吗?在

我首先尝试了insert查询,如下所示-

这是桌子:

cur.execute('''CREATE TABLE AccidentList (
        accidentId SERIAL PRIMARY KEY,
        cameraGeoLocation POINT,
        accidentTimeStamp TIMESTAMPTZ);''')

尝试1:

^{pr2}$

错误:

>;提示:psycopg2.ProgrammingError:列“camerageolocation”的类型是point,但expression的类型是numeric

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, '...


Tags: executedata错误linequerypsycopg2pointinsert