Skip to content

Instantly share code, notes, and snippets.

@filimonov
Last active July 10, 2018 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filimonov/57e270104a3e48d7fd6f70a3d4ec2b95 to your computer and use it in GitHub Desktop.
Save filimonov/57e270104a3e48d7fd6f70a3d4ec2b95 to your computer and use it in GitHub Desktop.
Reformat CSV to clickhouse-compatible TSV
#!/usr/bin/env python
import csv, sys
csv.register_dialect('clickhouse', escapechar="\\", doublequote=0, quotechar='\'',skipinitialspace = 0,delimiter = '\t', quoting=csv.QUOTE_NONE, lineterminator='\n')
csv.writer(sys.stdout, dialect='clickhouse').writerows(csv.reader(sys.stdin))
# install:
# put in $PATH
# chmod +x csv2tsv.py
# usage:
# cat file.csv | csv2tsv.py | clickhouse-client ... --query='INSERT ...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment