jackc / sqlfmt

SQL Formatter
Apache License 2.0
338 stars 23 forks source link

syntax error with vitess bootstrap sql files #1

Open tv42 opened 8 years ago

tv42 commented 8 years ago

Hi. I was curious about sqlfmt and fed it the first *.sql I could find, and got mysterious syntax errors:

$ cat $GOPATH/src/github.com/youtube/vitess/data/bootstrap/_vt_schema.sql 
CREATE DATABASE _vt;

CREATE TABLE _vt.replication_log (
  time_created_ns bigint primary key,
  note varchar(255));

CREATE TABLE _vt.reparent_log (
  time_created_ns bigint primary key,
  last_position varchar(255),
  new_addr varchar(255),
  new_position varchar(255),
  wait_position varchar(255),
  index (last_position));
$ sqlfmt $GOPATH/src/github.com/youtube/vitess/data/bootstrap/_vt_schema.sql 
2015/11/04 15:03:30 parse error: syntax error at character 328
Parse failed
$ head -1 $GOPATH/src/github.com/youtube/vitess/data/bootstrap/_vt_schema.sql | hexdump -C
00000000  43 52 45 41 54 45 20 44  41 54 41 42 41 53 45 20  |CREATE DATABASE |
00000010  5f 76 74 3b 0a                                    |_vt;.|
00000015
$ head -1 $GOPATH/src/github.com/youtube/vitess/data/bootstrap/_vt_schema.sql | sqlfmt
2015/11/04 15:03:38 parse error: syntax error at character 21
Parse failed
$ 
jackc commented 8 years ago

Unfortunately, sqlfmt is far from complete. It can handle pretty much anything that can happen in a select statement except CTEs, but not much else. You can look in the testdata directory to see examples of what it does do.