1

I would like to know if somebody knows a way to customize the csv output in htsql, and especially the delimiter and the encoding ?

I would like to avoid iterating over each result and find a way through configuration and/or extensions.

Thank in advance.

Anthony

dugres
  • 12,613
  • 8
  • 46
  • 51
trez
  • 478
  • 4
  • 10
  • I'm curious what encoding/delimiter you need and why you need it (compatibility with ...). We have a very pluggable extension mechanism, so there may be lots of options, for example, writing a formatter more specific (and helpful) to the program you are interfacing with. – clarkevans Apr 18 '12 at 13:30
  • Our need is for non-english Excel user where using latin-1 do not request any action while opening the file, whereas utf-8 may display wrong character and request to choose the encoding. Delimiter is ";" as it is the customer default. (else if not ";", Excel will request to explicitly validate your delimiter choice). Is there any documentation on how to write a custom formatter and plug it or should I dig in the code? Can you suggest a starting point? Thanks anyway for your quick feedback. – trez Apr 19 '12 at 08:35
  • Perhaps it might be useful for us to support 'xls' formatter for Excel using xlwt, would that solve the problem out of the gate? This might also provide a good example for writing a formatter. I'll write a blog entry in the next few weeks on custom formatters. Since we've not yet released 2.3.1 which completely re-does how formatters work (its on hold for documentation), so if you're going to play with formatters... please use tip at bitbucket: https://bitbucket.org/prometheus/htsql/overview – clarkevans Apr 19 '12 at 17:09
  • I just managed to write my custom extension implementing a custom bind, format and etc. But I changed htsql source code to do that. Is there a proper way to define the binding outside htsql itself? Through an extension maybe? – trez Apr 20 '12 at 09:57
  • trez: In the htsql implementation (almost) everything is an extension, so yes, it should be certainly possible, if not easy to do -- there are some demo extensions. I admit this isn't well documented though, I'll add that to my priority list. – clarkevans Apr 22 '12 at 00:09

1 Answers1

3

If you want TAB as a delimiter, use tsv format (e.g. /query/:tsv instead of /query/:csv).

There is no way to specify the encoding other than UTF-8. You can reencode the output manually on the client.

Kirill Simonov
  • 256
  • 1
  • 3