I don't understand the reference "2" in the following message. There is
only a primary key constraint on the named table. It is generated by
default and Im not inserting a value for it.
SQL0803N One or more values in the INSERT statement, UPDATE statement,
or foreign key update caused by a DELETE statement are not valid because
the primary key, unique constraint or unique index identified by "2"
constrains table "IS3.ENTITIES_P UB" from having duplicate rows for those
columns. SQLSTATE=23505
The DDL for the offending table:
CREATE TABLE IS3.ENTITIES_PU B
(ENTITY_ID INTEGER NOT NULL GENERATED BY DEFAULT
AS IDENTITY (START WITH 20, INCREMENT BY 1, CACHE 20, MINVALUE 20,
MAXVALUE 2147483647, NO CYCLE, NO ORDER),
NAMEX VARCHAR(50) NOT NULL,
CITY VARCHAR(30),
STATE VARCHAR(30),
COUNTRY VARCHAR(30) DEFAULT 'United States'
)
DATA CAPTURE NONE
IN USERSPACE1;
ALTER TABLE IS3.ENTITIES_PU B
LOCKSIZE ROW
APPEND OFF
NOT VOLATILE;
ALTER TABLE IS3.ENTITIES_PU B
ADD CONSTRAINT PRIMARY PRIMARY KEY
(ENTITY_ID
);
The failing statement:
merge into is3.entities_pu b t1
using an_pub_names_in t2
on t2.ranch=t1.nam ex
and t2.city=t1.city
and t2.state=t1.sta te
and t2.country=t1.c ountry
when not matched and t2.entity_id is null
then insert (namex,city,sta te,country)
values(ranch,ci ty,state,countr y);
only a primary key constraint on the named table. It is generated by
default and Im not inserting a value for it.
SQL0803N One or more values in the INSERT statement, UPDATE statement,
or foreign key update caused by a DELETE statement are not valid because
the primary key, unique constraint or unique index identified by "2"
constrains table "IS3.ENTITIES_P UB" from having duplicate rows for those
columns. SQLSTATE=23505
The DDL for the offending table:
CREATE TABLE IS3.ENTITIES_PU B
(ENTITY_ID INTEGER NOT NULL GENERATED BY DEFAULT
AS IDENTITY (START WITH 20, INCREMENT BY 1, CACHE 20, MINVALUE 20,
MAXVALUE 2147483647, NO CYCLE, NO ORDER),
NAMEX VARCHAR(50) NOT NULL,
CITY VARCHAR(30),
STATE VARCHAR(30),
COUNTRY VARCHAR(30) DEFAULT 'United States'
)
DATA CAPTURE NONE
IN USERSPACE1;
ALTER TABLE IS3.ENTITIES_PU B
LOCKSIZE ROW
APPEND OFF
NOT VOLATILE;
ALTER TABLE IS3.ENTITIES_PU B
ADD CONSTRAINT PRIMARY PRIMARY KEY
(ENTITY_ID
);
The failing statement:
merge into is3.entities_pu b t1
using an_pub_names_in t2
on t2.ranch=t1.nam ex
and t2.city=t1.city
and t2.state=t1.sta te
and t2.country=t1.c ountry
when not matched and t2.entity_id is null
then insert (namex,city,sta te,country)
values(ranch,ci ty,state,countr y);
Comment