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 1nXpds-0005f1-Qu for pgsql-general@arkaria.postgresql.org; Fri, 25 Mar 2022 19:30:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nXpdr-00070V-Fh for pgsql-general@arkaria.postgresql.org; Fri, 25 Mar 2022 19:30:35 +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 1nXpdr-0006zr-4t for pgsql-general@lists.postgresql.org; Fri, 25 Mar 2022 19:30:35 +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 1nXpdj-0005pS-W7 for pgsql-general@lists.postgresql.org; Fri, 25 Mar 2022 19:30:34 +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 22PJUP2J3457457; Fri, 25 Mar 2022 15:30:25 -0400 From: Tom Lane To: Rob Sargent cc: pgsql-general@lists.postgresql.org Subject: Re: Leading comments and client applications In-reply-to: <48a04123-7962-b1e0-4d01-63c202c10f1f@gmail.com> References: <265623A4-F304-4E68-90D0-343F614DB2B7@americanefficient.com> <3262782.1648223941@sss.pgh.pa.us> <48a04123-7962-b1e0-4d01-63c202c10f1f@gmail.com> Comments: In-reply-to Rob Sargent message dated "Fri, 25 Mar 2022 10:25:30 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3457455.1648236625.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 25 Mar 2022 15:30:25 -0400 Message-ID: <3457456.1648236625@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Rob Sargent writes: >> As far as the comparison behavior goes, psql's parser strips >> comments that start with double dashes, for $obscure_reasons. > That story aught to be worth a $beer or two Hmm. The original reasoning is lost in the mists of time; I dug in our git history and traced the behavior as far back as a45195a19 of 1999-11-04, but I'll bet a nickel that Peter doesn't remember exactly why he did that. But I can show you why I gave up on removing the behavior: it's an important part of psql's strategy of discarding leading whitespace before a query. Our regression test scripts are full of cases like -- comments here SELECT intentionally-wrong-query; and what they're expecting to get from that is output like ERROR: column "intentionally" does not exist LINE 1: SELECT intentionally-wrong-query; ^ When I changed psql's parser to not remove comments, that output suddenly changed to say "LINE 3:", because now the query string sent to the server included the "-- comments here" line as well as the blank line after it. While we could have changed all the expected output, or changed how the server counts lines within a query, we concluded that this would confuse too many people and break too many applications; so we left it alone. (As of v15, psql will send -- comments that begin *after* the first non-whitespace token of a query [1]. But leading comments and whitespace will still get stripped.) regards, tom lane [1] https://git.postgresql.org/gitweb/?p=3Dpostgresql.git&a=3Dcommitdiff&h= =3D83884682f4df96184549b91869a1cf79dafb4f94