diff --git a/packages/nocodb/src/lib/meta/api/columnApis.ts b/packages/nocodb/src/lib/meta/api/columnApis.ts index 598817a16e..aa034d4a6d 100644 --- a/packages/nocodb/src/lib/meta/api/columnApis.ts +++ b/packages/nocodb/src/lib/meta/api/columnApis.ts @@ -727,7 +727,19 @@ export async function columnUpdate(req: Request, res: Response) { const dbDriver = NcConnectionMgrv2.get(base); const driverType = dbDriver.clientType(); - + // MultiSelect to SingleSelect + if (column.uidt === UITypes.MultiSelect && colBody.uidt === UITypes.SingleSelect) { + if (driverType === 'mysql' || driverType === 'mysql2') { + await dbDriver.raw(`UPDATE ?? SET ?? = SUBSTRING_INDEX(??, ',', 1) WHERE ?? LIKE '%,%';`, [table.table_name, column.title, column.title, column.title]); + } else if (driverType === 'pg') { + await dbDriver.raw(`UPDATE ?? SET ?? = split_part(??, ',', 1);`, [table.table_name, column.title, column.title]); + } else if (driverType === 'mssql') { + await dbDriver.raw(`UPDATE ?? SET ?? = LEFT(cast(?? as varchar(max)), CHARINDEX(',', ??) - 1) WHERE CHARINDEX(',', ??) > 0;`, [table.table_name, column.title, column.title, column.title, column.title]); + } else if (driverType === 'sqlite3') { + await dbDriver.raw(`UPDATE ?? SET ?? = substr(??, 1, instr(??, ',') - 1) WHERE ?? LIKE '%,%';`, [table.table_name, column.title, column.title, column.title, column.title]); + } + } + // Handle migrations for (const op of column.colOptions.options.filter(el => el.order === null)) { op.title = op.title.replace(/^'/, '').replace(/'$/, '')