Re: Leading comments and client applications

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Leading comments and client applications
Date: 2022-03-25 19:35:13
Message-ID: f2d49d18-79be-0a41-67b4-b4939f1ca255@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 3/25/22 13:30, Tom Lane wrote:
> Rob Sargent<robjsargent(at)gmail(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Laurenz Albe 2022-03-26 05:08:40 Re: Leading comments and client applications
Previous Message Tom Lane 2022-03-25 19:30:25 Re: Leading comments and client applications