Skip to content

LEAST and GREATEST : TypeError: Object #<Object> has no method 'join' #104

Closed

Description

@gregaubert

When trying to use the GREATEST or LEAST functions with this exemple :

var alasql = require('alasql');
var tab = [{a: 1, b:4}, {a:5, b:3}];
alasql('SELECT GREATEST(a, b) as test FROM ?', tab);

We get the error _ has no method 'join' _ because we try to use join on the arguments object, and it's not real array, so it got no method join.

It is possible to solve it by calling the join method like this :

Array.prototype.join.call(arguments, ',')

But if I update alasql with this fix, then I get NaN results instead of the numbers :

 alasql('SELECT GREATEST(a, b) as test FROM ?', tab); 
// result : [ { test: NaN }, { test: NaN } ]

And the result of the join method called on the arguments in the GREATEST method gives this :

console.log(Array.prototype.join.call(arguments, ','));
// result : p['default']['a'],p['default']['b']

Is this correct ? Or could the problem come from that ?

Activity

  1. agershun commented on Mar 25, 2015

    @agershun
    Member

    Mea culpa!

    You can temporary fix it with:

        alasql.stdlib.GREATEST = function(){
              return 'Math.max('+Array.prototype.slice.call(arguments).join(',')+')'
        };
        alasql.stdlib.LEAST = function(){
              return 'Math.min('+Array.prototype.slice.call(arguments).join(',')+')'
        };

    See full example in jsFiddle

    I will fix this bug and update the library tonight.

  2. agershun commented on Mar 25, 2015

    @agershun
    Member

    BTW: You missed brackets in alasql() data argument:

        alasql('SELECT GREATEST(a, b) as test FROM ?', tab); // wrong
        alasql('SELECT GREATEST(a, b) as test FROM ?', [tab]); // correct
  3. gregaubert commented on Mar 25, 2015

    @gregaubert
    CollaboratorAuthor

    Oh yeah so that's the reason for the NaN values, my bad.

    For the temporary fix, you don't need to slice before the join, this works too :

        alasql.stdlib.GREATEST = function(){
              return 'Math.max('+Array.prototype.join.call(arguments, ',')+')'
        };
        alasql.stdlib.LEAST = function(){
              return 'Math.min('+Array.prototype.join.call(arguments, ',')+')'
        };
  4. agershun commented on Mar 25, 2015

    @agershun
    Member

    Wow! 👍

  5. agershun commented on Mar 25, 2015

    @agershun
    Member

    Fixed in develop branch (this fix will be relased in version 0.0.43)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions