I use R for this.
TextQL: Execute SQL Against CSV or TSV
31–40 of 95 posts
Re: TextQL: Execute SQL Against CSV or TSV
#32PostgreSQL does this out of the box with : CREATE EXTENSION file_fdw; CREATE SERVER import FOREIGN DATA WRAPPER file_fdw; CREATE FOREIGN TABLE foo ( col1 text, col2 text, ... ) SERVER import OPTIONS ( filename '/path/to/foo.csv', format 'csv' ); SELECT col1 FROM foo WHERE col2='x';
I personally have been using harelba’s q (the un-googleable utility), which is just fine.
It would be great not to shift gears into SQLite syntax and date formatting all the time. Does anyone know of a similar tool that runs over postgres?
Re: TextQL: Execute SQL Against CSV or TSV
#33Earlier quoted context omitted.
From the README: Key differences between textql and sqlite importing sqlite import will not accept stdin, breaking unix pipes. textql will happily do so. textql supports quote escaped delimiters, sqlite does not. textql leverages the sqlite in memory database feature as much as possible and only touches disk if asked.
But it is SQLite under the covers? A better title then would be an SQLite wrapper for use in shell pipelines.
The Readme is describing the differences in importing. I'm not sure how your distinction makes this any more clear.
Re: TextQL: Execute SQL Against CSV or TSV
#34Earlier quoted context omitted.
But it is SQLite under the covers? A better title then would be an SQLite wrapper for use in shell pipelines.
That's a silly complaint. It's a tool powered by SQLite. Under your extended definition, tools like web browsers (which use SQLite to power various things) would be SQLite wrappers.
Re: TextQL: Execute SQL Against CSV or TSV
#35Re: TextQL: Execute SQL Against CSV or TSV
#36q is out there for years, with a very large community.
q is a command line tool that allows direct execution of SQL-like queries on CSVs/TSVs (and any other tabular text files).
Re: TextQL: Execute SQL Against CSV or TSV
#37 ps aux | tail -n +2 | awk '{ printf("%s\t%s\n", $1, $4) }' | \
clickhouse-local -S "user String, mem Float64" \
-q "SELECT user, round(sum(mem), 2) as memTotal FROM table GROUP BY user ORDER BY memTotal DESC FORMAT Pretty"
┏━━━━━━━━━━┳━━━━━━━━━━┓
┃ user ┃ memTotal ┃
┡━━━━━━━━━━╇━━━━━━━━━━┩
│ clickho+ │ 0.7 │
├──────────┼──────────┤
│ root │ 0.2 │
├──────────┼──────────┤
│ netdata │ 0.1 │
├──────────┼──────────┤
│ ntp │ 0 │
├──────────┼──────────┤
│ dbus │ 0 │
├──────────┼──────────┤
│ nginx │ 0 │
├──────────┼──────────┤
│ polkitd │ 0 │
├──────────┼──────────┤
│ nscd │ 0 │
├──────────┼──────────┤
│ postfix │ 0 │
└──────────┴──────────┘
Has the advantage of being really fast.Re: TextQL: Execute SQL Against CSV or TSV
#38In SQLite you can just do sqlite> .import myfile.csv mytable sqlite> select ... What does this tool give you that SQLite doesn't do out of the box?
As a command-line tool it could serve as a more powerful replacement for unix utilities that I often use for simple analysis jobs: sort, uniq, wc, awk, sometimes cut and sed. I'm going to give it a try. It looks like textql loads everything into an in-memory SQLite instance, whereas I'd really like to see an approach that uses the SQLite's virtual table mechanism ( https://sqlite.org/vtab.html ), which would avoid th…
The streaming would make it memory efficient, and possibly able to handle some big data - maybe not true "Big Data", but certainly 10s of gigabytes.
Anyone want to take this idea into a GoFundMe site?
Re: TextQL: Execute SQL Against CSV or TSV
#39ClickHouse ships with a command line tool which does this (without the actual database server): ps aux | tail -n +2 | awk '{ printf("%s\t%s\n", $1, $4) }' | \ clickhouse-local -S "user String, mem Float64" \ -q "SELECT user, round(sum(mem), 2) as memTotal FROM table GROUP BY user ORDER BY memTotal DESC FORMAT Pretty" ┏━━━━━━━━━━┳━━━━━━━━━━┓ ┃ user ┃ memTotal ┃ ┡━━━━━━━━━━╇━━━━━━━━━━┩ │ clickho+ │ 0.7 │ ├──────────┼──…
Re: TextQL: Execute SQL Against CSV or TSV
#40In SQLite you can just do sqlite> .import myfile.csv mytable sqlite> select ... What does this tool give you that SQLite doesn't do out of the box?
It's discussed in the README: https://github.com/dinedal/textql#key-differences-between-te... > sqlite import will not accept stdin, breaking unix pipes. textql will happily do so. > textql supports quote escaped delimiters, sqlite does not. > textql leverages the sqlite in memory database feature as much as possible and only touches disk if asked.
#!/usr/bin/env rc
row_headers=''
output_mode=column
fn usage {
echo $0 usage
echo -o '#' which output mode to use
echo -r '#' if present, output row headers
echo -h '#' this message
}
while(~ $1 -*) {
switch($1) {
case -o
output_mode=$2
shift
case -r
row_headers='.headers on'
case -h
usage
exit 0
case *
echo Bad args: $*
usage
exit 1
}
shift
}
test $#* -ne 1 && echo Wrong number of arguments && usage && exit 1
sql_statement=$1
sqlite_bin=''
{ which sqlite > /dev/null >[2=1] && sqlite_bin=sqlite } || { which sqlite3 >/dev/null >[2=1] && sqlite_bin=sqlite3 }
table_name=atable
stdin_file=/proc/$pid/fd/0
{
echo .mode csv
echo .import $stdin_file $table_name
echo $row_headers
echo .mode $output_mode
echo $sql_statement
} | $sqlite_bin