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 1nXpiU-0005yr-Tj for pgsql-general@arkaria.postgresql.org; Fri, 25 Mar 2022 19:35:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nXpiT-0008Kv-OD for pgsql-general@arkaria.postgresql.org; Fri, 25 Mar 2022 19:35:21 +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 1nXpiT-0008Kj-Dh for pgsql-general@lists.postgresql.org; Fri, 25 Mar 2022 19:35:21 +0000 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nXpiP-0005sO-QB for pgsql-general@lists.postgresql.org; Fri, 25 Mar 2022 19:35:21 +0000 Received: by mail-pl1-x62c.google.com with SMTP id p17so9149328plo.9 for ; Fri, 25 Mar 2022 12:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to; bh=AbGEwQzgYdfzvnMBrlKvB6Cjhl/Um4cNSwCAt5nXgsg=; b=KbEu+y4rrSpNuKqCb/dmjZ+xewbddfai2K12wy4iA9Y9MI+W0aXmgabr37IMeuB0lc F3Xo5h8Qtu5IhABWG2yZaW/CXu0Ri0aXk9rvflL3Vrk3LZjvnAMPnWQg++ZnTBFdHxLT k20ADfwuiJC9fHrnrOtsjqewi1PTFpSfbhesc0dQaRBCLTqRGRKOttO14fxDrhu0z7m8 zoONDRPeFmfVC574sHYVCTBRp+1/kniunxWS3afATRyZX3U26Y+tbkNfLgobCMIQIIkl jSZitFYy3385ZCo+YT12cI3V/zJXGGer39g+MHQdM9CvIIVZ8/MPxnk1b9X2dUAQDgpF mGLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to; bh=AbGEwQzgYdfzvnMBrlKvB6Cjhl/Um4cNSwCAt5nXgsg=; b=1sCjaaYk8kJ8NY0bty1n4oDrULMbJ78359hDZy7eDXW6Xc6CUuiUoAjnN86PzvxLBZ Ehz/g7GUuigc85RsLSrmD1eyySmu/ZZa4kIUM/QxQgyrsD/YrHil40r233icE2Mh+m+0 g4qJn74JcouC1cFYUJk6p0igaB0mb2G6MvrDmuI0M62tz28HFOrFqVJdUBaJ7UqTXK1a JWZlywnWlf4zmTgMp9HhYjY9P4VoNa1eP9vG1fSpuTmRZmHOeUS/IifUlHcw4u8kqK2P SbEaZ4OByG7s/ODLG+12Ho0Zk9ViZZPSOTdcPZaJ4ohdMnDqRgeW+MisDrduCOc8kCZR rLDA== X-Gm-Message-State: AOAM530Vyii+9Lr+A0ZxYBkzOfEV4OMeI0xyoR7llht6PcLaDm/5WR6y PO7PksT2IVvIjW6sXhMvcLk= X-Google-Smtp-Source: ABdhPJx9AWh8G0zqex6DdRg7ISM5jO8OxdDGzL9w4BS/HxzwGYSEjCI2jY52yeEIdwjem80Uo5Ltug== X-Received: by 2002:a17:90a:5291:b0:1bb:ef4d:947d with SMTP id w17-20020a17090a529100b001bbef4d947dmr26672388pjh.243.1648236915589; Fri, 25 Mar 2022 12:35:15 -0700 (PDT) Received: from [10.128.71.194] ([155.98.131.2]) by smtp.gmail.com with ESMTPSA id ml16-20020a17090b361000b001c6c9141b0csm6751584pjb.45.2022.03.25.12.35.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Mar 2022 12:35:15 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------LGqU1IdgwiIijWAhxVDlcfWO" Message-ID: Date: Fri, 25 Mar 2022 13:35:13 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: Leading comments and client applications Content-Language: en-CA To: Tom Lane Cc: pgsql-general@lists.postgresql.org References: <265623A4-F304-4E68-90D0-343F614DB2B7@americanefficient.com> <3262782.1648223941@sss.pgh.pa.us> <48a04123-7962-b1e0-4d01-63c202c10f1f@gmail.com> <3457456.1648236625@sss.pgh.pa.us> From: Rob Sargent In-Reply-To: <3457456.1648236625@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------LGqU1IdgwiIijWAhxVDlcfWO Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 3/25/22 13:30, Tom Lane wrote: > 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=postgresql.git&a=commitdiff&h=83884682f4df96184549b91869a1cf79dafb4f94 Thank you for the indulgence! I clearly owe you (another) one. --------------LGqU1IdgwiIijWAhxVDlcfWO Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
On 3/25/22 13:30, Tom Lane wrote:
Rob Sargent <robjsargent@gmail.com> 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=postgresql.git&a=commitdiff&h=83884682f4df96184549b91869a1cf79dafb4f94
Thank you for the indulgence! I clearly owe you (another) one.
--------------LGqU1IdgwiIijWAhxVDlcfWO--