From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrus <kobruleht2@hot.ee>
Cc: pgsql-general@postgresql.org
Subject: Re: Include 3 previous tokens in syntax error message
Date: Sun, 27 Dec 2020 10:48:11 -0500
Message-ID: <1466590.1609084091@sss.pgh.pa.us> (raw)
In-Reply-To: <ed636acc-f4c4-7b50-3d59-fc727068e4c7@hot.ee>
References: <ed636acc-f4c4-7b50-3d59-fc727068e4c7@hot.ee>
Andrus <kobruleht2@hot.ee> writes:
> Postgres returns unreadable syntax error messageges like
> Syntax error at or near ')'
> How to fix this so that 3 last tokens are returned in message like
> Syntax error at or near ' i > )'
Our take on this is that it's the client code's responsibility to
present a useful error message using the error position info.
Thus, libpq for example has support for turning that into
postgres=# select (1 + 2));
ERROR: syntax error at or near ")"
LINE 1: select (1 + 2));
^
In a query spanning dozens of lines, that sort of localization
could be way more useful than what you suggest.
A driver that munges the user-supplied string is particularly
on the hook to do something useful, since the server is certainly
unable to reverse-engineer that.
The fact that basic syntax error messages come out like that is an
artifact of what the Bison parser generator does, it's not something
that PG developers chose. (And, by the same token, it's difficult
to get Bison to do something different.)
I'm loath to expend server-side effort on doing better, when it's
the client that knows how it's going to present the message and
what's the best way to display a syntax error. pgAdmin, for example,
has requirements completely different from text-based clients.
Making the basic error message longer could actually be
counterproductive for clients that are making an effort on this;
for example, a message incorporating three or four source tokens
might not fit on one line anymore.
In short, I think you should take your complaint to the authors
of whichever driver or application you're using. They really
ought to try at least as hard as libpq+psql do.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, kobruleht2@hot.ee
Subject: Re: Include 3 previous tokens in syntax error message
In-Reply-To: <1466590.1609084091@sss.pgh.pa.us>
References: <ed636acc-f4c4-7b50-3d59-fc727068e4c7@hot.ee> <1466590.1609084091@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox