关系“pk”已经存在于Postgresql 9.1中

时间:2013-03-29 15:01:26

标签: sql postgresql postgis postgresql-9.1 psql

我是Postgres / PostGIS的新手,目前正在关注PostGIS一书。当我尝试其中一个示例的查询时,我收到以下错误,指出relation "pk" already exists。这是否意味着2个表不能具有相同名称的约束?

查询:

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

1 个答案:

答案 0 :(得分:1)

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