Browse Source

fix(nocodb): AVG function handler return value correction

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5392/head
Pranav C 2 years ago
parent
commit
5670f51019
  1. 28
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/commonFns.ts

28
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/commonFns.ts

@ -91,24 +91,20 @@ export default {
),
};
},
AVG: (args: MapFnArgs) => {
AVG: async (args: MapFnArgs) => {
if (args.pt.arguments.length > 1) {
return {
builder: args.fn(
{
type: 'BinaryExpression',
operator: '/',
left: { ...args.pt, callee: { name: 'SUM' } },
right: { type: 'Literal', value: args.pt.arguments.length },
},
args.a,
args.prevBinaryOp
),
};
return args.fn(
{
type: 'BinaryExpression',
operator: '/',
left: { ...args.pt, callee: { name: 'SUM' } },
right: { type: 'Literal', value: args.pt.arguments.length },
},
args.a,
args.prevBinaryOp
);
} else {
return {
builder: args.fn(args.pt.arguments[0], args.a, args.prevBinaryOp),
};
return args.fn(args.pt.arguments[0], args.a, args.prevBinaryOp);
}
},
FLOAT: async (args: MapFnArgs) => {

Loading…
Cancel
Save