onConflictDoUpdate excluded with a dynamic column

Hey, I'm trying to perform an insert where it's possible that the record already exists, therefore I'm using onConflictDoUpdate, the problem I'm running into is that I can't dynamically set the column to update, here's my current approach:
export async function editGroupSettings(
  db: Db,
  option: string,
  groupId: number,
  userId: string,
  value: number,
) {
  await db
    .insert(groupAlertsConfigTable)
    .values({
      groupId: groupId,
      userId: userId,
      [option]: value,
    })
    .onConflictDoUpdate({
      target: [groupAlertsConfigTable.mafiaId, groupAlertsConfigTable.userId],
      set: {
        [option]: sql`EXCLUDED."${option}"`,
      },
      where: and(
        eq(groupAlertsConfigTable.groupId, groupId),
        eq(groupAlertsConfigTable.userId, userId),
      ),
    });
}

editGroupSettings(db, "minMCap", 1, "ry73wkah5ojhl76k", 2);

I'm getting the following error when executing this
PostgresError: column excluded.$4 does not exist
Was this page helpful?