pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Include 3 previous tokens in syntax error message
2+ messages / 2 participants
[nested] [flat]

* Include 3 previous tokens in syntax error message
@ 2020-12-27 14:48  Andrus <kobruleht2@hot.ee>
  0 siblings, 1 reply; 2+ messages in thread

From: Andrus @ 2020-12-27 14:48 UTC (permalink / raw)
  To: pgsql-general

Hi!

Postgres returns unreadable syntax error messageges like

Syntax error at or near ')'

If there are many ) characters in query, it is not possible to find the 
palce where error occurs.

STATEMENT_POSITION is difficult to use since drivers perform parameter 
replacements which makes this different from source position.

How to fix this so that 3 last tokens are returned in message like

Syntax error at or near ' i > )'

Andrus.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Include 3 previous tokens in syntax error message
@ 2020-12-27 15:48  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Andrus <kobruleht2@hot.ee>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2020-12-27 15:48 UTC (permalink / raw)
  To: Andrus <kobruleht2@hot.ee>; +Cc: pgsql-general

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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2020-12-27 15:48 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-12-27 14:48 Include 3 previous tokens in syntax error message Andrus <kobruleht2@hot.ee>
2020-12-27 15:48 ` Tom Lane <tgl@sss.pgh.pa.us>

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