diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2.ts index 0c382ea3b4..5ce2ade250 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/formulav2/formulaQueryBuilderv2.ts @@ -664,6 +664,20 @@ export default async function formulaQueryBuilderv2( sql = `COALESCE(${left}, '') ${pt.operator} COALESCE(${right},'')${colAlias}`; } + if (knex.clientType() === 'mysql2') { + sql = `IFNULL(${left} ${pt.operator} ${right}, ${ + pt.operator === '=' + ? pt.left.type === 'Literal' + ? pt.left.value === '' + : pt.right.value === '' + : pt.operator === '!=' + ? pt.left.type !== 'Literal' + ? pt.left.value === '' + : pt.right.value === '' + : 0 + }) ${colAlias}`; + } + const query = knex.raw(sql); if (prevBinaryOp && pt.operator !== prevBinaryOp) { query.wrap('(', ')');