-
Notifications
You must be signed in to change notification settings - Fork 689
From
Mathias Wulff edited this page May 23, 2024
·
9 revisions
Syntax:
SELECT ... FROM (table1|from-function|json-object|parameter), table2...
SEARCH selectors FROM (table|json-objects|from-function|parameter)From database table
alasql('SELECT * FROM albums');
alasql('SELECT * FROM mydb.test');From parameter
alasql(‘SELECT * FROM ?’,[singers]);From array parameter
alasql(‘SELECT * FROM [?]’,[singers]);From file (FROM-function)
alasql('SELECT * FROM XLSX(“medals.xlsx”)');From stdin (for Node.js)
alasql('SELECT * FROM TXT()');From SELECT statement
alasql('SELECT * FROM (SELECT * FROM (SELECT * FROM City))');- ? – just value
- [?] – converts array to array of arrays
[1,2,3] => [[1],[2],[3]]Array of objects
alasql(‘SELECT city.population FROM ? AS city’,[city]);Array of arrays
alasql(‘SELECT [0]+[1]*[2] FROM ?’, [data]);
Object
alasql(“SELECT [1] FROM ? WHERE [0] = ‘one’”,[{one:1,two:2}])String
alasql(“SELECT LEN([0]) FROM ?”,[“Multi \n line \n text”])String => array of lines
alasql('SELECT * FROM ? WHERE LEN([0]) > 10',[“abc\ncde”])
=> [[“abc”],[“cde”]]Objects => array of pairs key-value
{a:1,b:2} => [[“a”,1],[“b”,2]]FROM table alias
alasql('SELECT * FROM ? City');
alasql('SELECT * FROM album AS a');Examples:
alasql('SELECT * FROM cities'); var data = [{city:"Boston"}, {city:"Los Angeles"}];
alasql('SELECT * FROM ? ORDER BY city',[data]);You can also get data from stdin stream (for Node.js only). For example, how to calculate number of lines in incoming text file:
alasql('SELECT COUNT(*) FROM TXT()');Please note that you can avoid letting AlaSQL try to add extension to filenames by setting autoExt:false in the options given.
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo