几何值导入PostgreSQL+PostGIS

Geometry value into PostgreSQL+PostGIS

我在将 geometry 值插入 PostgreSQL/PostGIS 数据库时遇到问题。我正在使用 psycopg2 包。我想存储纬度和经度,我使用 geopy 库,下一个代码:

geolocator = Nominatim()
location = geolocator.geocode(name)

我很困惑 SQL 我必须写什么句子。我正在尝试

sql = """INSERT INTO Sensor(name, value, location, unit, frecuencyUpdate)
                 VALUES(%s, %s, ST_MakePoint(%s, %s),%s, %s)
                 RETURNING id;"""

 cur = conn.cursor()
 cur.execute(sql, (sensor.estacion, sensor.waterState, sensor.getLongitude(), sensor.getLatitude(), sensor.unit, sensor.frecuencyUpdate))

我收到错误:

"doesn't exits relation «sensor»"

有人可以帮助我吗?

你的 SQL 的 table 名字有一个大写的 S 但它没有被引用,所以 Postgres 正在寻找一个 table 小写字母。如果您使用大写字母创建 table,则必须引用它:

sql = """INSERT INTO \"Sensor\"(name, value, location, unit, frecuencyUpdate)
                 VALUES(%s, %s, ST_MakePoint(%s, %s),%s, %s)
                 RETURNING id;"""