harelba / q

q - Run SQL directly on delimited files and multi-file sqlite databases
http://harelba.github.io/q/
GNU General Public License v3.0
10.21k stars 423 forks source link

Setting default delimiter in .qrc config file? #298

Closed bigpresh closed 2 years ago

bigpresh commented 2 years ago

I may be missing something obvious but is there a way to set the default delimiter in the config?

I've tried what seems obvious:

[davidp@supernova:~]$ cat .qrc 
[options]
delimiter=,

but it explodes:

[davidp@supernova:~]$ q -H 'select * from test.csv where col1 = 3'
Traceback (most recent call last):
  File "/usr/bin/q", line 1940, in <module>
    run_standalone()
  File "/usr/bin/q", line 1664, in run_standalone
    default_delimiter = get_option_with_default(
  File "/usr/bin/q", line 1658, in get_option_with_default
    return p.get('options', option).decode('string-escape')
AttributeError: 'str' object has no attribute 'decode'

I almost always use q to query CSV files, and it's a bit annoying to have to tell it every time that the file uses commas as delimiters, otherwise:

[davidp@supernova:~]$ cat test.csv 
"col1","col2"
1,2
3,4
5,6

[davidp@supernova:~]$ q -H 'select * from test.csv where col1 = 3'
Warning: column count is one - did you provide the correct delimiter?
Bad header row: Header must contain only strings and not numbers or empty strings: 'col1,"col2"'
'col1,"col2"': Column name cannot contain commas
harelba commented 2 years ago

Hi,

Thanks for opening this.

Can you check which version of q you're using? It's probably an old one.

The current version is 3.1.6, and contains a fully refactored qrc mechanism.

Here are the relevant links. If things don't work with this new version, please contact me.

Installation Page

Version 3.1.6 Release

bigpresh commented 2 years ago

Ahhhh.

I'd installed the most recent distro-packed version, both on a Debian box and a Ubuntu 20.04.4 LTS workstation, and both got a much older version:

[davidp@supernova:~]$ q -v
q version 1.8
Copyright (C) 2012-2017 Harel Ben-Attia (harelba@gmail.com, @harelba on twitter)
http://harelba.github.io/q/

Having upgraded them to a non-prehistoric version (3.1.6 from the .deb download), all is well and the config file is recognised and I don't have to supply the delimiter every time.

Thanks for the prompt response, and thanks for a rather awesome tool!