【发布时间】:2011-01-02 16:31:35
【问题描述】:
我有一个包含数百万行的 postgres 数据库,它有一个名为 geom 的列,其中包含属性的边界。
我使用 python 脚本从该表中提取信息并将其重新插入到新表中。
当我在新表中插入时,脚本会出现以下错误:
Traceback (most recent call last):
File "build_parcels.py", line 258, in <module>
main()
File "build_parcels.py", line 166, in main
update_cursor.executemany("insert into parcels (par_id, street_add, title_no, proprietors, au_name, ua_name, geom) VALUES (%s, %s, %s, %s, %s, %s, %s)", inserts)
psycopg2.IntegrityError: new row for relation "parcels" violates check constraint "enforce_geotype_geom"
新表有一个检查约束 enforce_geotype_geom = ((geometrytype(geom) = 'POLYGON'::text) OR (geom IS NULL)) 而旧表没有,所以我猜那里有无用数据或非多边形(也许是多面数据?)在旧表中。我想将新数据保留为多边形,所以不想插入其他任何东西。
最初,我尝试使用标准 python 错误处理包装查询,希望哑几何行会失败但脚本会继续运行,但脚本已被编写为在最后提交而不是每一行,因此它不起作用。
我认为我需要做的是遍历旧表的几何行并检查它们是什么类型的几何图形,以便在插入新表之前确定是要保留还是丢弃它
解决这个问题的最佳方法是什么?
【问题讨论】:
标签: python postgresql postgis