diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 9f6d5a6c11..90a58a1bcb 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -1483,10 +1483,26 @@ export class ColumnsService { UITypes.MultiSelect, ].includes(column.uidt) ) { + const dbDriver = await reuseOrSave('dbDriver', reuse, async () => + NcConnectionMgrv2.get(source), + ); + const driverType = dbDriver.clientType(); + + let trimColumn = `??`; + if (driverType === 'mysql' || driverType === 'mysql2') { + trimColumn = `TRIM(BOTH ' ' FROM ??)`; + } else if (driverType === 'pg') { + trimColumn = `BTRIM(??)`; + } else if (driverType === 'mssql') { + trimColumn = `LTRIM(RTRIM(??))`; + } else if (driverType === 'sqlite3') { + trimColumn = `TRIM(??)`; + } + setStatement = baseUsers .map((user) => sqlClient.knex - .raw('WHEN ?? = ? THEN ?', [ + .raw(`WHEN ${trimColumn} = ? THEN ?`, [ column.column_name, user.email, user.id,