Skip to content

Commit 150b3fe

Browse files
improvement(tables): throw on ambiguous upsert instead of guessing the conflict column
1 parent 766ad33 commit 150b3fe

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

apps/sim/blocks/blocks/table.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Return ONLY the data JSON:`,
283283
id: 'conflictColumn',
284284
title: 'Conflict Column',
285285
type: 'short-input',
286-
placeholder: 'Unique column to match on (defaults to the first unique column)',
286+
placeholder: 'Unique column to match on (required if the table has multiple unique columns)',
287287
dependsOn: ['tableId'],
288288
condition: { field: 'operation', value: 'upsert_row' },
289289
},
@@ -646,7 +646,8 @@ Return ONLY the sort JSON:`,
646646
offset: { type: 'number', description: 'Query result offset' },
647647
conflictColumn: {
648648
type: 'string',
649-
description: 'Unique column to match on for upsert (defaults to the first unique column)',
649+
description:
650+
'Unique column to match on for upsert (required if the table has multiple unique columns)',
650651
},
651652
},
652653

apps/sim/lib/table/rows/service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,12 @@ export async function upsertRow(
492492
)
493493
}
494494
targetColumnKey = getColumnId(col)
495-
} else {
496-
// No conflict target specified — default to the first unique column.
495+
} else if (uniqueColumns.length === 1) {
497496
targetColumnKey = getColumnId(uniqueColumns[0])
497+
} else {
498+
throw new Error(
499+
`Table has multiple unique columns (${uniqueColumns.map((c) => c.name).join(', ')}). Specify a conflict column to indicate which one to match on.`
500+
)
498501
}
499502

500503
// Validate row data

0 commit comments

Comments
 (0)