pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Rob Sargent <robjsargent@gmail.com>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Leading comments and client applications
Date: Fri, 25 Mar 2022 15:30:25 -0400
Message-ID: <3457456.1648236625@sss.pgh.pa.us> (raw)
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>

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=83884682f4df96184549b9186...





view thread (11+ messages)  latest in thread

Message-ID: <3457456.1648236625@sss.pgh.pa.us>
Permalink:  ../3457456.1648236625@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3457456.1648236625@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, robjsargent@gmail.com
  Subject: Re: Leading comments and client applications
  In-Reply-To: <3457456.1648236625@sss.pgh.pa.us>
  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>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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