Я использую Posgres 8.4 и у меня есть следующая таблица
CREATE TABLE communitynetwork_listitem
(
id serial NOT NULL,
"MdUsr" integer,
"MdDT" timestamp with time zone NOT NULL,
"CrUsr" integer,
"CrDT" timestamp with time zone NOT NULL,
category_id character varying(15) NOT NULL,
"name" character varying(200) NOT NULL,
"order" integer NOT NULL,
"extraInfo" boolean NOT NULL,
"multiLineInfo" boolean NOT NULL,
"descrLabel" character varying(50) NOT NULL,
"decimalReq" boolean NOT NULL,
"decimalLabel" character varying(50) NOT NULL,
"decimalLabelDisplay" character varying(50) NOT NULL,
"descrLabelDisplay" character varying(50) NOT NULL,
CONSTRAINT communitynetwork_listitem_pkey PRIMARY KEY (id),
CONSTRAINT "category_id_refs_catId_69f2992c" FOREIGN KEY (category_id)
REFERENCES communitynetwork_listcategory ("catId") MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED,
CONSTRAINT communitynetwork_listitem_category_id_64fdc58a_uniq UNIQUE (category_id, name)
)
WITH (
OIDS=FALSE
);
Когда я попытался выполнить следующий запрос, он выдал ошибку, сообщающую, что я нарушил ограничение communitynetwork_listitem_pkey.Есть идеи, почему это может быть?
insert into communitynetwork_listitem ("MdUsr", "MdDT", "CrUsr", "CrDT", category_id, name, "order", "extraInfo", "multiLineInfo", "descrLabel", "decimalReq", "decimalLabel", "decimalLabelDisplay", "descrLabelDisplay")
select "MdUsr", "MdDT", "CrUsr", "CrDT", category_id, name, 0, "extraInfo", "multiLineInfo", "descrLabel", "decimalReq", "decimalLabel", "decimalLabelDisplay", "descrLabelDisplay"
from communitynetwork_listitem_import liImp
where not exists (select *
from communitynetwork_listitem li
where li.name = liImp.name
and li.category_id = liImp.category_id)