diff --git a/packages/nocodb-sdk/src/lib/formulaHelpers.ts b/packages/nocodb-sdk/src/lib/formulaHelpers.ts index 89479a121c..b3cc06d364 100644 --- a/packages/nocodb-sdk/src/lib/formulaHelpers.ts +++ b/packages/nocodb-sdk/src/lib/formulaHelpers.ts @@ -1594,7 +1594,11 @@ async function extractColumnIdentifierType({ res.dataType = FormulaDataTypes.STRING; break; case UITypes.Checkbox: - res.dataType = FormulaDataTypes.NUMERIC; + if (col.dt === 'boolean' || col.dt === 'bool') { + res.dataType = FormulaDataTypes.BOOLEAN; + } else { + res.dataType = FormulaDataTypes.NUMERIC; + } break; case UITypes.ID: case UITypes.ForeignKey: diff --git a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts index 739832e412..5a1884891a 100644 --- a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts +++ b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts @@ -889,20 +889,26 @@ async function _formulaQueryBuilder( // if operator is == or !=, then handle comparison with BLANK which should accept NULL and empty string if (pt.operator === '==' || pt.operator === '!=') { + for (const operand of ['left', 'right']) { + if ( + pt[operand].dataType === FormulaDataTypes.BOOLEAN && + pt[operand === 'left' ? 'right' : 'left'].dataType === + FormulaDataTypes.NUMERIC + ) { + pt[operand === 'left' ? 'right' : 'left'] = { + type: 'CallExpression', + arguments: [pt[operand === 'left' ? 'right' : 'left']], + callee: { + type: 'Identifier', + name: 'BOOLEAN', + }, + dataType: FormulaDataTypes.BOOLEAN, + }; + } + } if (pt.left.callee?.name !== pt.right.callee?.name) { // if left/right is BLANK, accept both NULL and empty string for (const operand of ['left', 'right']) { - if (pt[operand].type === FormulaDataTypes.BOOLEAN) { - pt[operand] = { - type: 'CallExpression', - arguments: [pt[operand]], - callee: { - type: 'Identifier', - name: 'BOOLEAN', - }, - }; - } - if ( pt[operand].type === 'CallExpression' && pt[operand].callee.name === 'BLANK' diff --git a/packages/nocodb/src/db/functionMappings/pg.ts b/packages/nocodb/src/db/functionMappings/pg.ts index 9ee7f2ba9b..5b36f24282 100644 --- a/packages/nocodb/src/db/functionMappings/pg.ts +++ b/packages/nocodb/src/db/functionMappings/pg.ts @@ -351,7 +351,7 @@ END ${colAlias}`, BOOLEAN: async (args: MapFnArgs) => { return { builder: args.knex.raw( - `(${(await args.fn(args.pt.arguments[0])).builder})::boolean ${ + `(${(await args.fn(args.pt.arguments[0])).builder})::boolean${ args.colAlias }`, ),