You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AVG over text joins the strings: AVG of '12' and '3' gives 61.5 #2763
AVG over text adds the strings together instead of ignoring them, so it returns a wrong number. SUM ignores text. Seen while checking the sqllogictest run (evidence/slt_lang_aggfunc.test), reproduced on develop (06211a0) and 4.20.1:
alasql('SELECT SUM(y) AS s, AVG(y) AS a FROM ?',[[{y: '12'},{y: '3'}]]);// alasql: [{a: 61.5}] ('12' + '3' joins to '123', divided by 2); SUM gives no value// SQLite: s = 15, a = 7.5alasql('SELECT SUM(y) AS s, AVG(y) AS a FROM ?',[[{y: '12'},{y: 3}]]);// alasql: [{s: 3, a: 61.5}]// SQLite: s = 15, a = 7.5
Cause: the AVG aggregate in src/423groupby.js adds each value with _SUM += (y || 0), which joins strings, and counts every value that is not NULL. SUM checks for numbers first.
Fix (4.x)
AVG follows the rule of SUM: values that are not numbers are ignored in the sum and in the count. The examples above then give no value and a = 3. Nobody can rely on 61.5, so this is not breaking.
changed the title [-]AVG and SUM over a text column give no value: SQLite gives 0[/-][+]AVG over text joins the strings: AVG of '12' and '3' gives 61.5[/+]on Oct 21, 2026
Activity
[-]AVG and SUM over a text column give no value: SQLite gives 0[/-][+]AVG over text joins the strings: AVG of '12' and '3' gives 61.5[/+]