AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.04k stars 659 forks source link

Concatenate Strings or Columns #473

Closed vivekratnavel closed 8 years ago

vivekratnavel commented 8 years ago

Is there an in-built function to concatenate columns or strings like CONCAT() in mysql?

mathiasrw commented 8 years ago

Hmmm... dont know why CONCAT() is not supported.

You can make a user defined function to let it work.

alasql.fn.CONCAT = function(){
return arguments.join('');
}

now it should work (Sorry - cant test it now)

This needs to be implemented as part of the library

nickdeis commented 8 years ago

@mathiasrw Close, but the arguments object is not an Array, so you'd have to do something like

alasql.fn.CONCAT = function(){
return Array.prototype.slice.call(arguments).join(' ');
}
mathiasrw commented 8 years ago

:+1:

Thanks for improvement...

JS - the language that keeps giving you surprises... :)

I knew that when you do a console.log(arguments) it spits out like an array - but only now do I realise that you cant join the damn thing

a = function(){console.log(arguments)}
a(3,4) // [3, 4]

a = function(){console.log(arguments.join(','))}
a(3,4) // Uncaught TypeError: arguments.join is not a function(…)
agershun commented 8 years ago

Just added CONCAT() to the standard library.

mathiasrw commented 8 years ago

Closed per request from #628