diff --git a/packages/nocodb-sdk/src/lib/formulaHelpers.ts b/packages/nocodb-sdk/src/lib/formulaHelpers.ts index 90183336e9..8f9436dbf5 100644 --- a/packages/nocodb-sdk/src/lib/formulaHelpers.ts +++ b/packages/nocodb-sdk/src/lib/formulaHelpers.ts @@ -1679,7 +1679,7 @@ export async function validateFormulaAndExtractTreeWithType({ const validateAndExtract = async (parsedTree: any) => { const res: { dataType?: FormulaDataTypes; - transform?: FormulaDataTypes; + cast?: FormulaDataTypes; errors?: Set; [key: string]: any; } = { ...parsedTree }; @@ -1790,9 +1790,6 @@ export async function validateFormulaAndExtractTreeWithType({ if (expectedArgType === FormulaDataTypes.NUMERIC) { key = 'msg.formula.numericTypeIsExpected'; message = 'Numeric type is expected'; - } else if (expectedArgType === FormulaDataTypes.STRING) { - key = 'msg.formula.stringTypeIsExpected'; - message = 'String type is expected'; } else if (expectedArgType === FormulaDataTypes.BOOLEAN) { key = 'msg.formula.booleanTypeIsExpected'; message = 'Boolean type is expected'; @@ -1812,12 +1809,12 @@ export async function validateFormulaAndExtractTreeWithType({ } } - // if expected type is string and arg type is not string, then transform it to string + // if expected type is string and arg type is not string, then cast it to string if ( expectedArgType === FormulaDataTypes.STRING && expectedArgType !== argPt.dataType ) { - argPt.transform = FormulaDataTypes.STRING; + argPt.cast = FormulaDataTypes.STRING; } } } diff --git a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts index 39d3923bd3..36b2bb4fb6 100644 --- a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts +++ b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts @@ -746,6 +746,23 @@ async function _formulaQueryBuilder( arg.fnName = pt.callee.name.toUpperCase(); arg.argsCount = pt.arguments?.length; }); + + // if cast is string, then wrap with STRING() function + if (pt.cast === FormulaDataTypes.STRING) { + return fn( + { + type: 'CallExpression', + arguments: [{ ...pt, cast: null }], + callee: { + type: 'Identifier', + name: 'STRING', + }, + }, + a, + prevBinaryOp, + ); + } + if (pt.type === 'CallExpression') { switch (pt.callee.name.toUpperCase()) { case 'ADD':