diff --git a/src/61date.js b/src/61date.js index 15fac261e2..6612913ceb 100644 --- a/src/61date.js +++ b/src/61date.js @@ -31,7 +31,7 @@ stdfn.COALESCE = function () { if (typeof arguments[i] == 'number' && isNaN(arguments[i])) continue; return arguments[i]; } - return undefined; + return null; // Change this line at the bottom of stdfn.COALESCE }; stdfn.USER = function () { diff --git a/test/test999.js b/test/test999.js new file mode 100644 index 0000000000..6ecbd6b995 --- /dev/null +++ b/test/test999.js @@ -0,0 +1,13 @@ +if (typeof module !== 'undefined' && typeof require !== 'undefined') { +var alasql = require('../dist/alasql.js'); +} + +describe('Test COALESCE bugfix', function () { +it('Should return NULL if all arguments are null', function () { +// Pass a JavaScript undefined variable as a parameter ($1) +var res = alasql('SELECT COALESCE(NULL, $0) AS result', [undefined]); +if (res[0].result !== null) { +throw new Error('COALESCE returned undefined instead of null'); +} +}); +});