linq2db icon indicating copy to clipboard operation
linq2db copied to clipboard

Suggestion: BulkCopy with ON CONFLICT

Open darko1979 opened this issue 1 year ago • 4 comments

I have a situation that is illustrated by following example:

CREATE TABLE IF NOT EXISTS "item"
(
  id INT NOT NULL,
  code VARCHAR(100) NOT NULL,
  CONSTRAINT pk_item PRIMARY KEY (id)
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_item_code ON item USING btree (code);

Now I want to do a bulk insert by ignore duplicates on unique column "code" and it can be done like this:

INSERT INTO item(id,code)
VALUES (1,'1'),(2,'2'),(3,'2'),(4,'4')
ON CONFLICT DO NOTHING;

Existing BulkCopy method does not have an option to add ON CONFLICT at the end of statement. Is it possible to add this option?

darko1979 avatar Oct 25 '23 10:10 darko1979

It is possible. PR is welcome, as we probably will not have it on our list soon.

MaceWindu avatar Oct 25 '23 15:10 MaceWindu

Is this specific database feature?

igor-tkachev avatar Jan 23 '24 00:01 igor-tkachev

postgres and sqlite

MaceWindu avatar Jan 23 '24 13:01 MaceWindu

We can add a database specific option.

igor-tkachev avatar Jan 24 '24 02:01 igor-tkachev