我是postgres和postgis的新手,我将数据从csv文件加载到postgres数据库,但问题是当我想添加一个新的几何列时。 谢谢你的帮助
try:
cursor.execute("""alter table Pluvometre add column geom geometry(point, 4326)
using st_setsrid(st_makepoint(X, Y),4326);""")
except:
print "Error add gemetry column"
my data:
--------
X Y ID nosico noi mt8_x mt8_y lat lon
-74.0313470791373 45.3929059093611 1 OBXL1011 33 263196.452317745 5028244.700001 45 -74
-73.9491598482168 45.39888024068 2 OBXL1021 21 269635.2727916759 5028869.415663255 45 -74
答案 0 :(得分:1)
USING子句不能与ADD COLUMN一起使用。见https://www.postgresql.org/docs/9.6/static/sql-altertable.html
在您的情况下,您需要两个语句:ALTER TABLE和UPDATE:
ALTER TABLE Pluvometre ADD COLUMN geom geometry(point, 4326);
UPDATE Pluvometre SET geom = st_setsrid(st_makepoint(X, Y),4326);