Postgresql 10 There is no unique or exclusion constraint matching the ON CONFLICT specification
I currently have a table which looks like this:
CREATE TABLE "PDPC".collection
(
col_no bigint NOT NULL DEFAULT nextval('"PDPC".collection_col_no_seq'::regclass),
q1 character varying(10000) COLLATE pg_catalog."default",
q2 character varying(10000) COLLATE pg_catalog."default",
q3 character varying(10000) COLLATE pg_catalog."default",
q4 character varying(10000) COLLATE pg_catalog."default",
dg_fkey bigint,
CONSTRAINT collection_pkey PRIMARY KEY (col_no),
CONSTRAINT collection_dg_fkey_fkey FOREIGN KEY (dg_fkey)
REFERENCES "PDPC".datagroup (dg_no) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE "PDPC".collection
OWNER to postgres;
I am trying to execute an UPSERT statement in PHP using postgresql, but i received
Fatal error: Uncaught PDOException: SQLSTATE[42P10]: Invalid column reference: 7 ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification in C:Apache24htdocsconsideration.php:77 Stack trace: #0 C:Apache24htdocsconsideration.php(77): PDOStatement->execute() #1 {main} thrown in C:Apache24htdocsconsideration.php on line 77
My web page currently has a form that takes in a user input of answers to four questions, and these questions will go into "PDPC'.collection table. I would like for it to INSERT or UPDATE according to the dm_fkey, which is the foreign key I have set for this table.
This is the UPSERT statment that I used.
INSERT INTO "PDPC".collection (q1, q2, q3, q4, dg_fkey)
VALUES (:q1, :q2, :q3, :q4, :dg_no)
ON CONFLICT(dg_fkey) DO UPDATE
SET q1=:q1, q2=:q2, q3=:q3, q4=:q4
postgresql update foreign-key php insert
New contributor
add a comment |
I currently have a table which looks like this:
CREATE TABLE "PDPC".collection
(
col_no bigint NOT NULL DEFAULT nextval('"PDPC".collection_col_no_seq'::regclass),
q1 character varying(10000) COLLATE pg_catalog."default",
q2 character varying(10000) COLLATE pg_catalog."default",
q3 character varying(10000) COLLATE pg_catalog."default",
q4 character varying(10000) COLLATE pg_catalog."default",
dg_fkey bigint,
CONSTRAINT collection_pkey PRIMARY KEY (col_no),
CONSTRAINT collection_dg_fkey_fkey FOREIGN KEY (dg_fkey)
REFERENCES "PDPC".datagroup (dg_no) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE "PDPC".collection
OWNER to postgres;
I am trying to execute an UPSERT statement in PHP using postgresql, but i received
Fatal error: Uncaught PDOException: SQLSTATE[42P10]: Invalid column reference: 7 ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification in C:Apache24htdocsconsideration.php:77 Stack trace: #0 C:Apache24htdocsconsideration.php(77): PDOStatement->execute() #1 {main} thrown in C:Apache24htdocsconsideration.php on line 77
My web page currently has a form that takes in a user input of answers to four questions, and these questions will go into "PDPC'.collection table. I would like for it to INSERT or UPDATE according to the dm_fkey, which is the foreign key I have set for this table.
This is the UPSERT statment that I used.
INSERT INTO "PDPC".collection (q1, q2, q3, q4, dg_fkey)
VALUES (:q1, :q2, :q3, :q4, :dg_no)
ON CONFLICT(dg_fkey) DO UPDATE
SET q1=:q1, q2=:q2, q3=:q3, q4=:q4
postgresql update foreign-key php insert
New contributor
Please register/merge your accounts and you'll be able to edit your question and accept an answer.
– yper-crazyhat-cubeᵀᴹ
5 hours ago
Conflicts happen due to unique or exclusion constraints, not from FOREIGN KEY constraints. Isdg_fkey
supposed to be unique?
– yper-crazyhat-cubeᵀᴹ
5 hours ago
add a comment |
I currently have a table which looks like this:
CREATE TABLE "PDPC".collection
(
col_no bigint NOT NULL DEFAULT nextval('"PDPC".collection_col_no_seq'::regclass),
q1 character varying(10000) COLLATE pg_catalog."default",
q2 character varying(10000) COLLATE pg_catalog."default",
q3 character varying(10000) COLLATE pg_catalog."default",
q4 character varying(10000) COLLATE pg_catalog."default",
dg_fkey bigint,
CONSTRAINT collection_pkey PRIMARY KEY (col_no),
CONSTRAINT collection_dg_fkey_fkey FOREIGN KEY (dg_fkey)
REFERENCES "PDPC".datagroup (dg_no) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE "PDPC".collection
OWNER to postgres;
I am trying to execute an UPSERT statement in PHP using postgresql, but i received
Fatal error: Uncaught PDOException: SQLSTATE[42P10]: Invalid column reference: 7 ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification in C:Apache24htdocsconsideration.php:77 Stack trace: #0 C:Apache24htdocsconsideration.php(77): PDOStatement->execute() #1 {main} thrown in C:Apache24htdocsconsideration.php on line 77
My web page currently has a form that takes in a user input of answers to four questions, and these questions will go into "PDPC'.collection table. I would like for it to INSERT or UPDATE according to the dm_fkey, which is the foreign key I have set for this table.
This is the UPSERT statment that I used.
INSERT INTO "PDPC".collection (q1, q2, q3, q4, dg_fkey)
VALUES (:q1, :q2, :q3, :q4, :dg_no)
ON CONFLICT(dg_fkey) DO UPDATE
SET q1=:q1, q2=:q2, q3=:q3, q4=:q4
postgresql update foreign-key php insert
New contributor
I currently have a table which looks like this:
CREATE TABLE "PDPC".collection
(
col_no bigint NOT NULL DEFAULT nextval('"PDPC".collection_col_no_seq'::regclass),
q1 character varying(10000) COLLATE pg_catalog."default",
q2 character varying(10000) COLLATE pg_catalog."default",
q3 character varying(10000) COLLATE pg_catalog."default",
q4 character varying(10000) COLLATE pg_catalog."default",
dg_fkey bigint,
CONSTRAINT collection_pkey PRIMARY KEY (col_no),
CONSTRAINT collection_dg_fkey_fkey FOREIGN KEY (dg_fkey)
REFERENCES "PDPC".datagroup (dg_no) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
WITH (
OIDS = FALSE
)
TABLESPACE pg_default;
ALTER TABLE "PDPC".collection
OWNER to postgres;
I am trying to execute an UPSERT statement in PHP using postgresql, but i received
Fatal error: Uncaught PDOException: SQLSTATE[42P10]: Invalid column reference: 7 ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification in C:Apache24htdocsconsideration.php:77 Stack trace: #0 C:Apache24htdocsconsideration.php(77): PDOStatement->execute() #1 {main} thrown in C:Apache24htdocsconsideration.php on line 77
My web page currently has a form that takes in a user input of answers to four questions, and these questions will go into "PDPC'.collection table. I would like for it to INSERT or UPDATE according to the dm_fkey, which is the foreign key I have set for this table.
This is the UPSERT statment that I used.
INSERT INTO "PDPC".collection (q1, q2, q3, q4, dg_fkey)
VALUES (:q1, :q2, :q3, :q4, :dg_no)
ON CONFLICT(dg_fkey) DO UPDATE
SET q1=:q1, q2=:q2, q3=:q3, q4=:q4
postgresql update foreign-key php insert
postgresql update foreign-key php insert
New contributor
New contributor
edited 5 hours ago
yper-crazyhat-cubeᵀᴹ
74.6k11126207
74.6k11126207
New contributor
asked 5 hours ago
RayRay
1
1
New contributor
New contributor
Please register/merge your accounts and you'll be able to edit your question and accept an answer.
– yper-crazyhat-cubeᵀᴹ
5 hours ago
Conflicts happen due to unique or exclusion constraints, not from FOREIGN KEY constraints. Isdg_fkey
supposed to be unique?
– yper-crazyhat-cubeᵀᴹ
5 hours ago
add a comment |
Please register/merge your accounts and you'll be able to edit your question and accept an answer.
– yper-crazyhat-cubeᵀᴹ
5 hours ago
Conflicts happen due to unique or exclusion constraints, not from FOREIGN KEY constraints. Isdg_fkey
supposed to be unique?
– yper-crazyhat-cubeᵀᴹ
5 hours ago
Please register/merge your accounts and you'll be able to edit your question and accept an answer.
– yper-crazyhat-cubeᵀᴹ
5 hours ago
Please register/merge your accounts and you'll be able to edit your question and accept an answer.
– yper-crazyhat-cubeᵀᴹ
5 hours ago
Conflicts happen due to unique or exclusion constraints, not from FOREIGN KEY constraints. Is
dg_fkey
supposed to be unique?– yper-crazyhat-cubeᵀᴹ
5 hours ago
Conflicts happen due to unique or exclusion constraints, not from FOREIGN KEY constraints. Is
dg_fkey
supposed to be unique?– yper-crazyhat-cubeᵀᴹ
5 hours ago
add a comment |
1 Answer
1
active
oldest
votes
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification in
This because dg_fkey
is a column referenced in a FOREIGN KEY
CONSTRAINT
and not an index. In fact, if you want that to be faster, you may consider additionally adding an index. From the docs on ON CONFLICT
You probably want something like this,
CREATE UNIQUE INDEX asdf ON pdpc.collection(dg_fkey);
Or add it the the ddl,
CREATE TABLE pdpc.collection
(
dg_fkey bigint UNIQUE
Then your upsert will work.
Also never use double-quotes on identifiers, that's a horrible practice in Pg
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Ray is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f226646%2fpostgresql-10-there-is-no-unique-or-exclusion-constraint-matching-the-on-conflic%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification in
This because dg_fkey
is a column referenced in a FOREIGN KEY
CONSTRAINT
and not an index. In fact, if you want that to be faster, you may consider additionally adding an index. From the docs on ON CONFLICT
You probably want something like this,
CREATE UNIQUE INDEX asdf ON pdpc.collection(dg_fkey);
Or add it the the ddl,
CREATE TABLE pdpc.collection
(
dg_fkey bigint UNIQUE
Then your upsert will work.
Also never use double-quotes on identifiers, that's a horrible practice in Pg
add a comment |
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification in
This because dg_fkey
is a column referenced in a FOREIGN KEY
CONSTRAINT
and not an index. In fact, if you want that to be faster, you may consider additionally adding an index. From the docs on ON CONFLICT
You probably want something like this,
CREATE UNIQUE INDEX asdf ON pdpc.collection(dg_fkey);
Or add it the the ddl,
CREATE TABLE pdpc.collection
(
dg_fkey bigint UNIQUE
Then your upsert will work.
Also never use double-quotes on identifiers, that's a horrible practice in Pg
add a comment |
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification in
This because dg_fkey
is a column referenced in a FOREIGN KEY
CONSTRAINT
and not an index. In fact, if you want that to be faster, you may consider additionally adding an index. From the docs on ON CONFLICT
You probably want something like this,
CREATE UNIQUE INDEX asdf ON pdpc.collection(dg_fkey);
Or add it the the ddl,
CREATE TABLE pdpc.collection
(
dg_fkey bigint UNIQUE
Then your upsert will work.
Also never use double-quotes on identifiers, that's a horrible practice in Pg
ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification in
This because dg_fkey
is a column referenced in a FOREIGN KEY
CONSTRAINT
and not an index. In fact, if you want that to be faster, you may consider additionally adding an index. From the docs on ON CONFLICT
You probably want something like this,
CREATE UNIQUE INDEX asdf ON pdpc.collection(dg_fkey);
Or add it the the ddl,
CREATE TABLE pdpc.collection
(
dg_fkey bigint UNIQUE
Then your upsert will work.
Also never use double-quotes on identifiers, that's a horrible practice in Pg
edited 4 hours ago
answered 4 hours ago
Evan CarrollEvan Carroll
31.1k865206
31.1k865206
add a comment |
add a comment |
Ray is a new contributor. Be nice, and check out our Code of Conduct.
Ray is a new contributor. Be nice, and check out our Code of Conduct.
Ray is a new contributor. Be nice, and check out our Code of Conduct.
Ray is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f226646%2fpostgresql-10-there-is-no-unique-or-exclusion-constraint-matching-the-on-conflic%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please register/merge your accounts and you'll be able to edit your question and accept an answer.
– yper-crazyhat-cubeᵀᴹ
5 hours ago
Conflicts happen due to unique or exclusion constraints, not from FOREIGN KEY constraints. Is
dg_fkey
supposed to be unique?– yper-crazyhat-cubeᵀᴹ
5 hours ago