Re: BUG #13832: Syntax errors are extremely unfriendly - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #13832: Syntax errors are extremely unfriendly
Date
Msg-id 1419.1450973473@sss.pgh.pa.us
Whole thread Raw
In response to BUG #13832: Syntax errors are extremely unfriendly  (tdhutt@gmail.com)
Responses Re: BUG #13832: Syntax errors are extremely unfriendly
List pgsql-bugs
tdhutt@gmail.com writes:
> When you have a syntax error in PostgreSQL (or MySQL for that matter) you
> get a message like this:
>> ERROR: syntax error at or near "FROM"
>> Position: 8
> This is not very user-friendly to put it mildly!

Well, at least some of that is on the head of whatever client-side
software you're using.  psql, for example, produces an error cursor
like this:

regression=# select * from from tab;
ERROR:  syntax error at or near "from"
LINE 1: select * from from tab;
                      ^

> Compare this with Clang's
> error messages (http://clang.llvm.org/diagnostics.html) which give you the
> exact location of the error, and also what was expected, and even
> suggestions to fix it!

As far as raw syntax errors go, we're pretty much limited by what Bison
will do; we're unlikely to implement our own parser from scratch just
to improve this.  We do go to considerable lengths for semantic errors,
eg in PG 9.5 you might get something like this for a misspelled column
name:

regression=# select unnique1 from tenk1;
ERROR:  column "unnique1" does not exist
LINE 1: select unnique1 from tenk1;
               ^
HINT:  Perhaps you meant to reference the column "tenk1.unique1".

            regards, tom lane

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #13831: Server Closed Connection Unexpectedly
Next
From: Michael Paquier
Date:
Subject: Re: BUG #13822: Slave terminated - WAL contains references to invalid page