I am new to Postgres/PostGIS, currently following a PostGIS book. When I tried one of their example's query, I get the error below stating that the relation "pk" already exists
. Does this mean that 2 tables cannot have constraints with the same names?
Query:
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'));
Error:
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
Yes. You need to use a different name within a database
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.