diff --git a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts index e7b056c5bf..38c2997117 100644 --- a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts +++ b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts @@ -1,5 +1,6 @@ import jsep from 'jsep'; import { + FormulaDataTypes, jsepCurlyHook, UITypes, validateFormulaAndExtractTreeWithType, @@ -21,7 +22,6 @@ import { validateDateWithUnknownFormat, } from '~/helpers/formulaFnHelper'; import FormulaColumn from '~/models/FormulaColumn'; -import { Source } from '~/models'; const logger = new Logger('FormulaQueryBuilderv2'); @@ -835,6 +835,30 @@ async function _formulaQueryBuilder( if (pt.operator === '==') { pt.operator = '='; + // if left/right is of different type, convert to string and compare + if ( + pt.left.dataType !== pt.right.dataType && + [pt.left.dataType, pt.right.dataType].every( + (type) => type !== FormulaDataTypes.NULL, + ) + ) { + pt.left = { + type: 'CallExpression', + arguments: [pt.left], + callee: { + type: 'Identifier', + name: 'STRING', + }, + }; + pt.right = { + type: 'CallExpression', + arguments: [pt.right], + callee: { + type: 'Identifier', + name: 'STRING', + }, + }; + } } if (pt.operator === '/') {