Bug: [self-hosted] : CSV Import Fails with "This record already exists" on PostgreSQL but works on MySQL

Description:

When using the CSV import feature to update existing records in a table, PostgreSQL throws a “This record already exists” error. This error does not occur when using MySQL.

Example:

test table,title is PRIMARY KEY,the new data is

title,name
1,5
2,5
3,3

PG ‘s CREATE TABLE SQL:

CREATE TABLE test (
“id” int4 NOT NULL DEFAULT nextval(‘test_id_seq’::regclass),
“created_at” timestamp(6),
“updated_at” timestamp(6),
“created_by” varchar COLLATE “pg_catalog”.“default”,
“updated_by” varchar COLLATE “pg_catalog”.“default”,
“nc_order” numeric,
“title” text COLLATE “pg_catalog”.“default” NOT NULL,
“name” int8,
CONSTRAINT “test_pkey” PRIMARY KEY (“title”)
)

Analysis suggests:

this is caused by differences in how MySQL and PostgreSQL handle upsert operations (updating existing records based on a primary key). Switching from using the bulkDataInsert API to the bulkDataUpsert API should resolve this problem.

I am not familiar with the NocoDB codebase and am unsure where to make this specific code change.

// nocodb\packages\nocodb\src\controllers\bulk-data-alias.controller.ts
// bulkDataUpsert
@post([‘/api/v1/db/data/bulk/:orgs/:baseName/:tableName/upsert’])

Issue #9837

@hengke Thanks for creating the issue on Github. We will follow it up with Engineering team