Skip to content

Commit de36e33

Browse files
committed
fix dysfunctional unique operation in tables
1 parent 2afe917 commit de36e33

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

apps/sim/lib/table/service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,11 +1691,11 @@ export async function updateColumnConstraints(
16911691
}
16921692

16931693
if (data.unique === true && !column.unique) {
1694-
const duplicates = await db.execute(
1694+
const duplicates = (await db.execute(
16951695
sql`SELECT ${userTableRows.data}->>${sql.raw(`'${escapedName}'`)} AS val, count(*) AS cnt FROM ${userTableRows} WHERE table_id = ${data.tableId} AND ${userTableRows.data} ? ${column.name} AND ${userTableRows.data}->>${sql.raw(`'${escapedName}'`)} IS NOT NULL GROUP BY val HAVING count(*) > 1 LIMIT 1`
1696-
)
1696+
)) as { val: string; cnt: number }[]
16971697

1698-
if (duplicates.rows.length > 0) {
1698+
if (duplicates.length > 0) {
16991699
throw new Error(`Cannot set column "${column.name}" as unique: duplicate values exist`)
17001700
}
17011701
}

0 commit comments

Comments
 (0)