我是Postgres/PostGIS的新手,目前正在读一本PostGIS的书。当我尝试他们的一个例子的查询时,我得到了下面的错误,指出relation "pk" already exists。这是否意味着两个表不能有同名的约束?
查询:

CREATE TABLE roads(gid serial PRIMARY KEY, road_name character varying(100));
SELECT AddGeometryColumn('public', 'roads', 'geom', 4269, 'LINESTRING',2);

CREATE TABLE roads_NE(CONSTRAINT pk PRIMARY KEY (gid))
INHERITS (roads);

ALTER TABLE roads_NE
ADD CONSTRAINT chk CHECK (state
IN ('MA', 'ME', 'NH', 'VT', 'CT', 'RI'));

CREATE TABLE roads_SW(CONSTRAINT pk PRIMARY KEY (gid))
INHERITS (roads);

ALTER TABLE roads_SW
ADD CONSTRAINT chk CHECK (state IN ('AZ', 'NM', 'NV'));

错误:
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "pk" for table "roads_sw"


ERROR:  relation "pk" already exists

********** Error **********

ERROR: relation "pk" already exists
SQL state: 42P07

最佳答案

对。您需要在数据库中使用其他名称

关于sql - 关系“pk”已经存在于Postgresql 9.1中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15705838/

10-16 16:49