I am doing a bulk insertion of duplicate values (duplicate type and uuid) using the below Postgres query.
I see an error in my logs like ActiveRecord::StatementInvalid: PG::CardinalityViolation: ERROR: ON CONFLICT DO UPDATE command cannot affect row a second time HINT: Ensure that no rows proposed for insertion within the same command have duplicate constrained values.
Why is this conflict resolution not working?
ActiveRecord::Base.connection.execute <<-POSTGRESQL
INSERT INTO #{Movie.table_name} (#{headers})
VALUES #{values}
ON CONFLICT (uuid, type) DO UPDATE SET video_id = EXCLUDED.video_id,
status = 1,
category = EXCLUDED.category, updated_at = EXCLUDED.updated_at
POSTGRESQL
CREATE TABLE movies (
id integer NOT NULL,
video_id integer NOT NULL,
category integer NOT NULL,
uuid character varying NOT NULL,
data json DEFAULT '{}'::json,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
type character varying DEFAULT 'FeatureLengthVideo'::character varying,
status integer DEFAULT 0 NOT NULL,
);