I'm using python and psycopg2 to insert a dict to my PostgreSQL database.
I have postgres version 13.2
At the moment I only have the code below to execute :
INSERT INTO movie_data(title, description, rating, published, cast_and_crew, age_group, country)
VALUES ('movie name', 'something', 8, 2020, 'an actor', 'pg-13', 'GB')
But because I already have this row in my db I get the 'already exists' error.
I've tried the ON CONFLICT DO NOTHING but I get the error below :
there is no unique or exclusion constraint matching the ON CONFLICT specification
What's the best way to ignore the duplicate rows and keep on inserting?
I'm new to SQL so if anyone could explain and include the whole code for this purpose I would really appreciate it.
UPDATE : below is my CREATE TABLE statement
CREATE TABLE public.movie_data
(
title text COLLATE pg_catalog."default" NOT NULL,
description text COLLATE pg_catalog."default" NOT NULL,
published integer,
cast_and_crew text COLLATE pg_catalog."default",
age_group text COLLATE pg_catalog."default",
country text COLLATE pg_catalog."default",
rating integer,
CONSTRAINT movie_data_pkey PRIMARY KEY (title, description)
)
TABLESPACE pg_default;
ALTER TABLE public.movie_data
OWNER to postgres;
CREATE TABLEstatement with all constraints. Don't you have a primary key?INSERTstatement withON CONFLICTclause? Update your question with this information.