Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ktYHS-0001wz-64 for pgsql-general@arkaria.postgresql.org; Sun, 27 Dec 2020 15:48:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ktYHQ-0001ay-D6 for pgsql-general@arkaria.postgresql.org; Sun, 27 Dec 2020 15:48:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ktYHQ-0001ar-5W for pgsql-general@lists.postgresql.org; Sun, 27 Dec 2020 15:48:24 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ktYHN-00074R-N6 for pgsql-general@postgresql.org; Sun, 27 Dec 2020 15:48:23 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 0BRFmB9m1466591; Sun, 27 Dec 2020 10:48:11 -0500 From: Tom Lane To: Andrus cc: pgsql-general@postgresql.org Subject: Re: Include 3 previous tokens in syntax error message In-reply-to: References: Comments: In-reply-to Andrus message dated "Sun, 27 Dec 2020 16:48:39 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1466589.1609084091.1@sss.pgh.pa.us> Date: Sun, 27 Dec 2020 10:48:11 -0500 Message-ID: <1466590.1609084091@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrus 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