2

我正在通过“PostGIS in Action”一书学习 PostgreSQL 和 PostGIS。我的问题来自 Pg。清单 3.4 中的 66。

我的代码如下:

CREATE TABLE ch03.paris_polygons(tags hstore, CONSTRAINT paris_polygons_pk PRIMARY KEY (gid)
)
INHERITS (ch03.paris);

ALTER TABLE ch03.paris_polygons NO INHERIT ch03.paris;
INSERT INTO ch03.paris_polygons(osm_id, ar_num, geom, tags, feature_name, feature_type)
SELECT osm_id, ar_num, ST_Multi(geom) As geom, tags, tags->'name',
COALESCE(tags->'tourism', tags->'railway','other')::varchar(50) As feature_type
FROM ch03.paris_hetero
WHERE ST_GeometryType(geom) LIKE '%Polygon';
SELECT populate_geometry_columns('ch03.paris_polygons'::regclass);
ALTER TABLE ch03.paris_polygons INHERIT ch03.paris;

运行代码后我收到此错误:

ERROR: child table "paris_polygons" has different type for column "geom"
SQL state: 42804

我用谷歌搜索找到了这个:

-204 (ECPG_INT_FORMAT)

The host variable is of type int and the datum in the database is of a different type and contains a value that cannot be interpreted as an int. The library uses strtol() for this conversion. (SQLSTATE 42804)

psql 命令会帮助我了解如何合并这些命令吗?

再次感谢所有的帮助!

4

2 回答 2

2

我刚碰到这个。这本书很可能在您(和我)正在查看的代码片段中忘记了这一步。但是,如果您继续阅读下一页,它们仅显示 LINESTRING 分区表的构造,那里有一条关键线,他们在 POLYGON 分区表构造中忘记了:

ALTER TABLE ch03.paris_polygons
ADD CONSTRAINT enforce_geotype_geom
CHECK (geometrytype(geom) = 'POLYGON'::TEXT);

一旦我添加了该约束,错误就消失了,基本上它导致发生的原因是允许 geom 列继承父 geom 列类型,而不是它假设基于的 geometry('polygon',SRID) 类型数据加载,并离开约束来管理类型限制。

于 2013-06-13T20:23:57.170 回答
0

我遇到了同样的错误。我尝试改用“MULTIPOLYGON”:

ALTER TABLE ch03.paris_polygons
ADD CONSTRAINT enforce_geotype_geom
CHECK (geometrytype(geom) = 'MULTIPOLYGON'::TEXT);
于 2015-01-19T09:24:51.873 回答