-
Notifications
You must be signed in to change notification settings - Fork 664
AlaSQL CLI
Mathias Rangel Wulff edited this page Mar 14, 2017
·
5 revisions
AlaSQL can be used in a console by installing it globally: npm install alasql -g
Usage:
alasql "sql-statement" [ params ] - Run SQL statement
alasql --file file.sql [ params ] - (or -f) Run SQL from file
alasql --version - (or -v) Echo AlaSQL version
Samples:
alasql 'select 2+2'
alasql 'select count(*) from txt()' < city.txt
alasql 'select * into xlsx("./data/city") from txt("city.txt")'
Examples:
Number of lines in text file with length more than 20 characters
alasql 'select value count(*) from txt("README.md") where length([0]) > 20'
Convert XLSX file to JSON
> alasql "SELECT * INTO json('my.json') from xlsx('cities.xlsx',{headers:true}) WHERE population > 20000000"
Simple calculator
> alasql 'VALUE OF SELECT 2*2'
4
?
will be replaced with the corresponding n'th argument so alasql "select ?+?" 10 20
corresponds to alasql select 10+20
> alasql "VALUE OF SELECT 20-?+?" 5 100
115
More examples:
alasql "select [1] from tab('./mytext.txt') where [0] = 1"
# From command file
alasql -f myprogram.sql
# like grep
alasql "select * from csv(?) where [0] != 1 and [1] like 'A%'" mytext.csv
# like calculator
alasql "select 2*2"
# Process Excel file
alasql "select [2] from xls(?) where [0]>0 and [1] in ('Cuba','Swiss')" mysheet.xlsx
# Join TAB and xlsx
alasql "select a.* from tab(?) as a left join xls(?) as b on a[0] = b[0] where b[0] != 2" sales.txt cities.xls
(To get value instead of a JSON you can prepend VALUE OF
to the SELECT
)
© 2014-2024, Andrey Gershun & Mathias Rangel Wulff
Please help improve the documentation by opening a PR on the wiki repo