jackc / sqlfmt

SQL Formatter
Apache License 2.0
338 stars 23 forks source link

Parsing fails for unquoted identifiers #9

Closed mxmCherry closed 6 years ago

mxmCherry commented 6 years ago

Did go get -u github.com/jackc/sqlfmt/cmd/sqlfmt a few minutes ago and trying to run it:

$ echo 'SELECT * FROM table' | sqlfmt
2017/11/15 01:03:53 parse error: syntax error at character 20
Parse failed

That's, umm, a bit surprising, as I'm quite used to write PG queries without quoting tables.

When you quote the table name - it works fine:

$ echo 'select * from "table"' | sqlfmt 
select
  *
from
  "table"

Seen this comment: https://github.com/jackc/sqlfmt/issues/7#issuecomment-326985548 so not actually expecting a fix (if it should be "fixed" at all?), just logging an issue.

Also, a bit of offtop question - it seems to support only SELECT statements, right? (as seen in sql.y file)

jackc commented 6 years ago

Yes, it only supports selects. And I think what is happening with "table" is it is considered a key word. Trying it with a different table name works.

$ echo 'SELECT * FROM foo' | sqlfmt
select
  *
from
  foo
mxmCherry commented 6 years ago

Oh, right, did not think about that - makes sense, thank you.